I need to generate PPM's as raw data sources for one program. I have a bunch of png's as Input, which I'm going to convert ppm's. When I try a tool like mogrify
it generates files, but these are unreadable to any image viewer programs such as GIMP:
mogrify -format ppm *.png
I have installed netpbm
package. I tried to open some other random PPM's from other places, any image viewer can open and read those files, the problem exists with my own generated files. The files created with mogrify
seem to have the right size for their resolution and contains bits.
In hex file viewer working file header looks like:
P6 640 480 25
Mine generated with Imagemagick:
P7 WIDTH 640 HEIGHT 480 DEPTH 3 MAXVAL 255 TUPLTYPE RGB ENDHD
Probably I need to give Imagemagick some other parameters to make correct file format, but what? Or is there another tool which can easily convert png's to ppm's?
Best Answer
If you take a look at the wikipedia pages for PPM and PAM it says that the magic numbers for PPM are as follows:
excerpt from PPM wikipedia page
Whereas with the PAM format it's magic number is P7. Also it was the following differences from the older formats (PPM, PNM, PGM, PBM):
excerpt from PAM wikipedia page
Example
If I convert a PNG file to a PPM file using
mogrify
I get the following:convert blah.png to blah.ppm:
file info:
identify info:
hex header info:
As you can see,
mogrify
correctly generated a PPM file (see the P6).So what's wrong?
I'm wondering if there is something special about your source images that you're converting to PPM, which the PPM format doesn't support, and mogrify is not able to handle that automatically.
I would suggest interrogating the source image using the
Edit #1identify
command:The OP posted the original image here. Running this image through myself I couldn't reproduce his result where
mogrify
would return a PAM file rather than a PPM file.generated ppm:
original png & new ppm files:
header info from files:
The file converted successfully for me. Running
display some.ppm
displayed the file so I'm not sure what to make of this. I did notice that the OP's identify command showed the files as sRGB whlie on my system these files show up as "8-bit DirectClass". The differences between these 2 is detailed here, but I'm not sure what to make of it.While researching this I came across several threads where there were bugs in ImageMagick related to sRBG and PNG. Here's a link to one example.