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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
xinito

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

Post by xinito » 2007-01-02T13:33:35-07:00

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

xinito

Post by xinito » 2007-01-02T13:41:48-07:00

Please discard the question. I figured it out after browsing some old articles. Use compress to force P5 :D

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony » 2007-01-03T19:01:22-07:00

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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

tedder
Posts: 1
Joined: 2019-05-17T15:47:49-07:00
Authentication code: 1152

Re:

Post by tedder » 2019-05-17T15:53:33-07:00

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.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post by anthony » 2019-05-19T16:51:27-07:00

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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply