cjpeg
Convert image files to JPEG format
SYNOPSIS
cjpeg [options] [inputfile]
PARAMETERS
-quality N
Set the compression quality factor to N (0-100). Higher values yield better quality but larger files.
-optimize
Perform optimization of Huffman coding tables. This usually results in slightly smaller files but takes longer.
-progressive
Create a progressive JPEG file. Progressive JPEGs display a low-resolution version first, then gradually improve detail.
-baseline
Force creation of a baseline JPEG file (the default for most JPEGs). This ensures maximum compatibility.
-grayscale
Create a grayscale JPEG file, discarding color information.
-fastcrush
Use a faster, but slightly less effective, algorithm for Huffman table selection. Often used with -optimize.
-outfile filename
Specify the output JPEG file name. If omitted, output is sent to standard output.
-arithmetic
Use arithmetic coding instead of Huffman coding. This is less common due to patent issues and slower performance, though it can yield slightly smaller files.
-idct METHOD
Specify the IDCT (Inverse Discrete Cosine Transform) algorithm to use. Methods include int (integer), simple (simple integer), fast (fast integer), float (floating point).
-color
Specify the input color space. Common options include rgb, cmyk, ycck.
-restart N
Add N-sample restart markers to the JPEG stream. This improves error resilience and allows for partial decoding.
-smooth N
Perform an N-point smoothing of the input image before compression. (Requires libjpeg-turbo).
-maxmemory N
Set the maximum memory to use in kilobytes for image processing.
-verbose
Print more information about the compression process, including progress and statistics.
-version
Print the cjpeg version number and exit.
DESCRIPTION
The cjpeg command is a utility from the Independent JPEG Group (IJG) JPEG library, often distributed as part of libjpeg-turbo or mozjpeg. Its primary function is to convert various image formats, such as PPM, PGM, BMP, and TGA, into the highly compressed JPEG format. cjpeg applies lossy compression, which means some image data is discarded to achieve smaller file sizes, particularly useful for web graphics and storage. Users can control the compression quality, optimize Huffman tables, and select various encoding modes like progressive or baseline JPEG. It is a fundamental tool for preparing images for scenarios where file size efficiency is crucial.
CAVEATS
• Lossy Compression: JPEG is a lossy format. Each time an image is saved in JPEG format (especially at lower qualities), some data is permanently lost. Repeated re-compression of JPEGs can lead to significant visual degradation.
• Quality Trade-offs: Balancing file size and visual quality is crucial. Very low quality settings (e.g., below 50) often result in noticeable compression artifacts.
• Color Space Handling: Incorrect handling of color spaces (e.g., RGB vs. CMYK) can lead to undesirable color shifts or incorrect rendering in the output.
• Arithmetic Coding: While potentially offering slightly better compression, arithmetic coding is rarely used due to historical patent issues and slower processing times. It's also not universally supported by all JPEG decoders.
• Input Formats: cjpeg typically only accepts raw image formats like PPM, PGM, BMP, or TGA. It cannot directly compress common formats like PNG or TIFF; these must be converted first.
<B>SUPPORTED INPUT FORMATS</B>
cjpeg primarily accepts raw image formats such as Portable PixMap (.ppm), Portable GrayMap (.pgm), Windows Bitmap (.bmp), and Truevision TGA (.tga). It does not directly read more complex formats like PNG or TIFF. Users typically convert these formats to PPM/PGM first before feeding them to cjpeg.
<B>DEFAULT OUTPUT</B>
By default, cjpeg writes the resulting JPEG data to standard output. This allows for piping its output to other commands or redirecting it to a file using shell redirection (e.g., cjpeg input.ppm > output.jpg). The -outfile option provides an alternative for direct file output.
HISTORY
cjpeg originated as part of the Independent JPEG Group's (IJG) reference implementation of the JPEG standard. The IJG library (libjpeg) became the de facto standard for JPEG encoding and decoding on Unix-like systems. Over time, several highly optimized forks and implementations emerged, most notably libjpeg-turbo (focused on speed using SIMD instructions) and mozjpeg (focused on achieving even smaller file sizes at high quality settings, often used for web optimization). cjpeg remains a core component of these distributions, providing a command-line interface to their powerful JPEG compression capabilities.