Linux Commands Examples

A great documentation place for Linux commands


convert a Portable Network Graphics file into portable anymap

see also : pnmtopng - pnmgamma


pngtopnm [-verbose] [-alpha | -mix] [-background color]
[-gamma value] [-text file] [-time] [pngfile]

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!


name=`echo $file | sed 's/\.png$//'`
pngtopnm $file >$name.pnm && pnmtops -nocenter -nosetpage $name.pnm >$name.eps && rm $name.pnm
pngtopnm "$1" > $t.pnm
#pngtopnm -alpha "$1" | pgmtopbm -threshold | convert -negate pbm:- pbm:$t.pbm
#pngtopnm -alpha "$1" | pgmtopbm -threshold | convert -negate pbm:- pbm:$t.pbm
pngtopnm -alpha "$1" | pgmtopbm -threshold > $t.pbm
pnmcomp -alpha=$t.pbm $t.pnm $t.pbm $t.2.pnm
pngtopnm "$1" > $t.pnm
#pngtopnm -alpha "$1" | pgmtopbm -threshold | convert -negate pbm:- pbm:$t.pbm
#pngtopnm -alpha "$1" | pgmtopbm -threshold | convert -negate pbm:- pbm:$t.pbm
pngtopnm -alpha "$1" | pgmtopbm -threshold > $t.pbm
ppmtowinicon -andppms $t.pnm $t.pbm > "$2"
exit 1
pngtopnm img/"$1" | pnmtoplainpnm > "$1".txt
pngtopnm "$INPUT_FILE" | cpaldjvu - "$INPUT_FILE".djvu
ls -l "$INPUT_FILE" "$INPUT_FILE".djvu
pngtopnm $1 | ppmtolss16 \#cdcfd5=7 \#ffffff=1 \#000000=0 \#c90000=15 > $2


Reads a Portable Network Graphics as input. Produces a portable anymap as output. The type of the output file depends on the input file - if it’s black & white, a pbm file is written, else if it’s grayscale a pgm file, else a ppm file.



Display the format of the input file and the type of the output file. If the chunks are part of the png-file, the alpha, transparency and gamma-values will be indicated.


Output the alpha channel or transparency mask of the image. The result is either a pbm file or pgm file, depending on whether different levels of transparency appear.


Compose the image with the transparency or alpha mask against a the background. When a background chunk is available that color is taken, else black will do.

-background color

If no background color chunck is present in the png-file, or when another color is required this parameter can be used to set the background color of images. This is especially useful for alpha-channel images or those with transparency chunks. The format, to specify the color in, is either (in the case of orange) "1.0,0.5,0.0", where the values are floats between zero and one, or with the syntax "#RGB", "#RRGGBB" or "#RRRRGGGGBBBB" where R, G and B are hexa-decimal numbers.

-gamma value

Converts the image to a new display-gamma value. When a gAMA chunk is present in the png-file, the image-gamma value will be used. When not, the image-gamma is considered to be 1.0. Based on the image-gamma and the display-gamma given with this option the colors written to the pnm-file will be adjusted.
Because the gamma’s of uncompensated monitors are around 2.6, which results in an image-gamma of 0.45, some typical situations are: when the image-gamma is 0.45 (use -verbose to check) and the picture is too light, your system is gamma-corrected, so convert with "-gamma 1.0". When no gAMA chunk is present or the image-gamma is 1.0, use 2.2 to make the picture lighter and 0.45 to make the picture darker.

-text file

Writes the tEXt and zTXt chunks to a file, in a format as described in the pnmtopng man-page. These chunks contain text comments or annotations.


Prints the tIME chunk to stderr.

All flags can be abbreviated to their shortest unique prefix.


Instead of pngtopnm|pnmtoxxx, a specific converter should be used, if available. E.g. ptot (PNG to TIFF conversion), etc.


There could be an option to read the comment text from pnm comments instead of a separate file.

The program could be much faster, with a bit of code optimizing.

see also

pnmtopng , ptot, pnmgamma , pnm


Copyright (C) 1995-1997 by Alexander Lehmann
and Willem van Schaik.

How can this site be more helpful to YOU ?

give  feedback