LinuxCommandLibrary

pamtopng

Convert PAM image format to PNG

TLDR

Convert the specified PAM image to PNG

$ pamtopng [path/to/image.pam] > [path/to/output.png]
copy

Mark the specified color as transparent in the output image
$ pamtopng [[-t|-transparent]] [color] [path/to/image.pam] > [path/to/output.png]
copy

Include the text in the specified file as tEXt chunks in the output
$ pamtopng [[-te|-text]] [path/to/file.txt] [path/to/image.pam] > [path/to/output.png]
copy

Cause the output file to be interlaced in Adam7 format
$ pamtopng [[-in|-interlace]] [path/to/image.pam] > [path/to/output.png]
copy

SYNOPSIS

pamtopng [-alpha=outnone|outalpha|outbgcolor|outtransparent] [-transparent=color] [-bgcolor=color] [-interlace] [-compression=1-9] [-notext] [pamfile]

PARAMETERS

-alpha=outnone|outalpha|outbgcolor|outtransparent
    Controls alpha channel output: omit (outnone), as PNG alpha (outalpha), transparent pixels (outtransparent), or blend with background (outbgcolor). Default: outalpha.

-transparent={rgb|hsl|gray|integer|fraction|percent}value
    Sets fully transparent color in output PNG (-alpha=outtransparent). Color specs per Netpbm conventions.

-bgcolor={rgb|hsl|gray|integer|fraction|percent}value
    Background color for alpha blending (-alpha=outbgcolor). Default: black.

-interlace
    Produce interlaced (Adam7) PNG for progressive loading.

-compression=1-9
    PNG compression level (1=fast/large, 9=slow/small). Default: 6.

-notext
    Omit PAM text comments from PNG text chunks.

DESCRIPTION

pamtopng is a command-line tool from the Netpbm suite that reads a PAM (Portable Arbitrary Map) image and writes it as a PNG (Portable Network Graphics) file. PAM is Netpbm's flexible format supporting arbitrary channels like RGB, alpha, grayscale, and custom data, while PNG offers lossless compression, transparency, and broad compatibility.

pamtopng excels at mapping PAM's advanced features to PNG, especially handling alpha transparency via multiple output modes. It supports PNG interlacing for progressive display and adjustable compression for optimizing file size. Input comes from stdin or a file; output goes to stdout, fitting Netpbm pipelines.

Ideal for batch conversion, scripting, or when PAM serves as an intermediate format in editing workflows. Unlike older pnmtopng, it fully leverages PAM's multi-channel capabilities, producing feature-rich PNGs with text comments (unless suppressed). Limitations include PNG's 4-channel max (RGBA), so excess PAM channels are discarded.

CAVEATS

Discards PAM channels beyond PNG's RGBA limit; no animation or metadata beyond basics. Requires libpng; output size grows with compression tweaks.

EXAMPLES

pamtopng image.pam > image.png
pamtopng -alpha=outbgcolor -bgcolor=white -compression=9 input.pam > out.png

STANDARDS

Follows PNG 1.2 spec; uses zlib compression. Compatible with Netpbm stdin/stdout piping.

HISTORY

Introduced in Netpbm 10.22 (2005) alongside PAM format by Jef Poskanzer. Evolved with PNG/libpng updates; supersedes pnmtopng for PAM inputs. Actively maintained in Netpbm releases.

SEE ALSO

pngtopam(1), pnmtopng(1), pamtomp(1), pam(5), png(5)

Copied to clipboard