LinuxCommandLibrary

cjpeg

Convert image files to JPEG format

SYNOPSIS

cjpeg [options] [infile]

PARAMETERS

-quality N[,N]
    Set JPEG quality (1-100, higher better; optional chroma quality)

-grayscale
    Force grayscale (monochrome) output

-rgb
    Input file is truecolor RGB

-optimize
    Optimize Huffman tables after input (smaller files)

-outfile name
    Write output to named file (default: stdout)

-scale M/N
    Scale output (M/N = 1/8,1/4,1/2,1/1)

-verbose
    Enable progress and statistics report

-dct int|float
    DCT method: integer (faster) or floating-point

-arithmetic
    Use arithmetic entropy coding (not JPEG standard)

-restart N
    Restart interval in MCUs (0=disable)

-smooth N
    Smooth level (0-100; reduces edge artifacts)

-maxmemory Nk
    Maximum memory to use (in kB)

-sample HxV[,...]
    Chroma subsampling factors

-scans file
    Use multiple-scan file for progressive JPEG

-progressive
    Create progressive JPEG file

-version
    Print version and exit

DESCRIPTION

cjpeg is a command-line utility from the Independent JPEG Group's (IJG) jpeg software package. It converts raster image files in formats like PPM, PGM, GIF, BMP, and Targa into highly compressed JPEG images.

The tool excels in balancing image quality and file size through adjustable quantization tables, chroma subsampling, entropy coding, and optional progressive or optimized output. It supports grayscale conversion, RGB input handling, smoothing to reduce artifacts, and DCT (Discrete Cosine Transform) methods for encoding.

Ideal for batch processing or scripting, cjpeg outputs to stdout by default (use redirection or -outfile), making it versatile for pipelines with tools like ImageMagick. It handles color space conversions automatically but offers fine control for advanced users. Performance scales with options like memory limits and restart markers for robustness over slow networks. Widely used in Linux environments for legacy and efficient JPEG creation.

INPUT FORMATS

Supports PPM/PGM (portable pixmap/graymap), GIF, BMP, Targa (TGA), and raw RGB. Detects format automatically.

EXAMPLES

cjpeg -quality 90 input.ppm > output.jpg
cjpeg -optimize -scale 1/2 -grayscale image.gif -outfile small.jpg

HISTORY

Developed by the Independent JPEG Group (IJG) starting in 1991 as part of their public-domain JPEG library and utilities. Evolved through versions up to 9e (2022), focusing on standards compliance, performance, and portability. Remains a staple in Linux distros despite alternatives like libjpeg-turbo.

SEE ALSO

djpeg(1), jpegtran(1), rdjpgcom(1), wrjpgcom(1)

Copied to clipboard