jpegtopnm
Convert JPEG images to PNM image format
TLDR
Convert JPEG/JFIF image to a PPM or PGM image
Display version
SYNOPSIS
jpegtopnm [options] [filename]
PARAMETERS
-dct float|integer
Select DCT method: float for higher precision (slower), integer for speed.
-fix
Use nonzero values for chroma DC coefficients (fixes some decoder bugs).
-noscale
Disable all color quantization and chroma subsampling upsampling.
-nosmooth
Disable fancy upsampling of chroma components.
-optimize
Optimize entropy encoding parameters (smaller files, slightly slower).
-quiet
Suppress all warning and informational messages.
-scale N/D
Scale output dimensions by ratio N/D (e.g., 1/2, 1/4, 1/8).
-verbose
Enable verbose status messages.
-maxmemory N[KM]
Limit memory usage to N kilobytes or megabytes.
-maxpixels N
Abort if image exceeds N pixels (prevents DoS).
-rgb
Convert to RGB colorspace (default is Adobe transform).
-report
Report dimensions, etc., to stderr.
DESCRIPTION
jpegtopnm is a command-line utility from the Netpbm suite that converts JPEG (Joint Photographic Experts Group) files into PNM (Portable Anymap) format. PNM encompasses PBM (bitmap), PGM (grayscale), and PPM (pixmap/color) formats. It automatically detects input image type: grayscale JPEGs yield PGM output, while color ones produce PPM.
The tool leverages the libjpeg library from the Independent JPEG Group for decoding. It supports common JPEG features like baseline sequential JPEG (JFIF) and offers options for DCT (Discrete Cosine Transform) method selection, smoothing, scaling, and memory limits. This makes it ideal for batch processing, image manipulation pipelines with other Netpbm tools (e.g., pnmscale, ppmtopng), or integration into scripts.
Key strengths include high compatibility with standard JPEGs, customizable quality trade-offs via options like -dct float for precision or -optimize for compressed tables, and robust error handling for corrupted files. Output preserves image dimensions and color fidelity where possible, though chroma subsampling in JPEG may require upsampling adjustments.
CAVEATS
Supports only baseline JPEG (JFIF/AVI); progressive and lossless JPEG have limited support. No EXIF or metadata preservation. Large images may consume significant memory without limits. Outputs raw PNM without headers unless piped.
EXAMPLES
jpegtopnm image.jpg > image.ppm
jpegtopnm -scale 1/2 -dct float large.jpg | pnmscale 2 2 > resized.ppm
jpegtopnm -verbose -maxpixels 10000000 *.jpg
INPUT/OUTPUT
Reads from stdin or file; writes to stdout. Use pnmtopnm family for chaining. Grayscale input yields PGM; color yields PPM.
HISTORY
Part of Netpbm toolkit, started by Jef Poskanzer in 1988. jpegtopnm added ~1990s, wrapping libjpeg (IJG, 1991+). Maintained in Netpbm releases; integrates with modern libjpeg-turbo for speed.


