Page 1 of 1

How to save PGM in Raw(binary) format instead of ascii?

Posted: 2007-01-02T13:33:35-07:00
by xinito
I am using C++ API for Magick Image. Sometimes, when I use image.write("***.pgm"), it will write out a ascii format pgm. Is there a way that I can specify the Magick to write in raw(binary) format?

Thanks

Posted: 2007-01-02T13:41:48-07:00
by xinito
Please discard the question. I figured it out after browsing some old articles. Use compress to force P5 :D

Posted: 2007-01-03T19:01:22-07:00
by anthony
What compress did to you to select between P2 and P5 (text and binary) NetPBM formats?

At the moment I only mention the use of the "pnmnoraw" program, though direct Im control would be better.

See IM example notes on this format.
http://www.cit.gu.edu.au/~anthony/graph ... ts/#netpbm
use in creating simple images for Resized gradients...
http://www.cit.gu.edu.au/~anthony/graph ... ent_resize
and the last example for...
http://www.cit.gu.edu.au/~anthony/graph ... files/#txt

Re:

Posted: 2019-05-17T15:53:33-07:00
by tedder
anthony wrote: 2007-01-03T19:01:22-07:00 What compress did to you to select between P2 and P5 (text and binary) NetPBM formats?
I'm going to necrothread this (12 years!), but hopefully helpful to future googlers (or duckduckgo, or whatever is being used in 2031).

To go to TEXT (P2) mode, use "-compress None". Examples:

Code: Select all

convert input.png -compress None out.pgm
convert singlefile.pgm -compress None singlefile.pgm
To go to BINARY (P5) mode, use "+compress". Examples:

Code: Select all

convert input.png +compress out.pgm
convert singlefile.pgm +compress singlefile.pgm
This comes from the documentation for the -compress flag:
Specify +compress to store the binary image in an uncompressed format.

Re: How to save PGM in Raw(binary) format instead of ascii?

Posted: 2019-05-19T16:51:27-07:00
by anthony
Yes it was added to IM Examples all those years ago...

PbmPlus / NetPBM Image File Format: PBM PGM PPM PNM PAM
http://www.imagemagick.org/Usage/formats/#pbmplus