1

I am studying RWH's Ch12 Barcode Recognition. For understanding the contents more deeply, I want to generate a barcode with the file format ppm from scratch, but it is difficult for me to get a file *.ppm. Generally, the free online Barcode Generator such as here or Zint Barcode Studio 2.4, it only can generate file format *.png or *.jpg, so that I must convert *.png into *.ppm by online converter or Gimp , but the produced *.ppm can not be processed by Barcode Recongnition.

For this problem, I want to directly produce a file *.ppm using Java library ZXing, but I have a same question that it seemly can not produce *.ppm directly.

what should I do? I hope you tell what (at best free) software or library can generate directly *.ppm?

duplode
  • 33,731
  • 7
  • 79
  • 150
abelard2008
  • 1,984
  • 1
  • 20
  • 35
  • PPM is a very simple file format, you should just read the specs and figure out why your parser fails – Niklas B. Dec 27 '14 at 10:15
  • yes format is very simple, search for "man pbm" or hit the netpbm website and read the docs there. – Jasen Dec 27 '14 at 10:22
  • @NiklasB., Jasen, Thank you! You are right, PPM is very simple, but the contents in *.PPM may be not simple such as Barcode image, so I am afraid I can not handle it and submit such a question! – abelard2008 Dec 27 '14 at 11:47
  • Couldn't you just use a paint program, perhaps in combination with e.g. `pngtopnm`? – SamB Dec 28 '14 at 04:13
  • @SamB, Thank you! Can you explain more? – abelard2008 Dec 28 '14 at 04:23

1 Answers1

1

Netpbm contains tools to convert popular formats to pbm.

pngtopnm < file.png | ppmtopgm | pgmtopbm > file.ppm

pngtopnm may convert directly to pgm or ppm it depends on the the colour-space of the input file.

you may need pnmtoplainpnm on the end of the pipeline if your program is expecting plain ascii pbm

pngtopnm < file.png | ppmtopgm | pgmtopbm | pnmtoplainpnm > file.ppm

use jpeg2pnm instead of pngtopnm for jpg images.

Other free image editing tools such as the gimp, imagemagick, and fly may also support saving images as pbm.

Jasen
  • 11,837
  • 2
  • 30
  • 48
  • ~Jasen, yes gimp can export *.jpg or *.png into *.ppm, but the produced *.ppm can not be correctly recognized by `RWH's PNM`, but `RWH's PNM` can handle the file getting from `pngtopnm < file.png > file.ppm` – abelard2008 Dec 27 '14 at 11:54