pnmtojpeg
Convert PNM images to JPEG format
TLDR
Read a PNM image as input and produce a JPEG/JFIF/EXIF image as output
Display version
SYNOPSIS
pnmtojpeg [options] [pnmfile]
PARAMETERS
-quality N
Sets the desired output quality level for the JPEG image. N is an integer between 0 (lowest quality, highest compression) and 100 (highest quality, lowest compression). The default is usually 75.
-optimize
Performs optimization of the entropy encoding parameters. This can result in a smaller file size for the same image quality but may take longer to encode.
-progressive
Creates a progressive JPEG file. Progressive JPEGs display in a series of passes, gradually refining the image quality, which can be beneficial for web viewing.
-grayscale
Forces the output JPEG image to be grayscale, even if the input PNM image is color (PPM). This is useful for reducing file size when color information is not needed.
-rgb
Forces the output JPEG image to be color (RGB), even if the input PNM image is grayscale (PGM) or monochrome (PBM). Note that a PGM input will result in a color JPEG with identical R, G, B channels.
-smooth N
Applies a smoothing filter to the input image before JPEG compression. N is an integer between 1 and 100, controlling the degree of smoothing. Higher values result in more smoothing.
-outfile filename
Specifies the output file for the JPEG image. If this option is not used, the JPEG image is written to standard output.
pnmfile
The path to the input PNM image file. If no file is specified, pnmtojpeg reads the PNM image from standard input.
DESCRIPTION
The pnmtojpeg command, part of the Netpbm suite of graphics utilities, transforms images in the Portable Anymap (PNM) format into the widely used JPEG format. It can accept any of the PNM sub-formats: PBM (Portable Bitmap), PGM (Portable Graymap), or PPM (Portable Pixmap). By default, pnmtojpeg reads the PNM image from standard input and writes the resulting JPEG image to standard output, allowing it to be easily integrated into shell pipelines. Users can control the JPEG compression quality, create progressive JPEGs for faster web display, and apply various other encoding options to fine-tune the output.
CAVEATS
JPEG is a lossy compression format, meaning some image data is discarded during compression. The quality setting directly impacts the amount of data loss. Repeated re-saving of a JPEG image can lead to cumulative degradation. The -arithmetic option (not listed above as it's less common) produces files that may not be universally supported by older or less common JPEG decoders.
HISTORY
pnmtojpeg is part of the extensive Netpbm package, a collection of utilities for manipulating graphic images. Its core functionality often relies on the widely used independent JPEG Group (IJG) library (or its successor, libjpeg-turbo), which provides the actual JPEG encoding algorithms. This connection ensures compatibility and adherence to JPEG standards. It serves as a user-friendly wrapper for cjpeg in many Netpbm installations, streamlining the conversion process from Netpbm's native formats to JPEG.