jpegoptim
Optimize JPEG files for smaller size
TLDR
Optimise a set of JPEG images, retaining all associated data
Optimise JPEG images, stripping all non-essential data
Force the output images to be progressive
Force the output images to have a fixed maximum filesize
SYNOPSIS
jpegoptim [options] filename(s)
PARAMETERS
-h, --help
Display help information and exit.
-V, --version
Output version information and exit.
-d, --dest=dir
Specify a destination directory for optimized files. Original files remain untouched.
-f, --force
Force optimization even if the file size does not decrease. Overwrites the original file by default.
-n, --noaction
Do not actually optimize files; just print statistics. Useful for testing or previewing changes.
-m, --max=quality
Set the maximum image quality factor (0-100, default: 95). Lower values result in smaller files but lower quality.
-s, --strip-all
Strip all markers (comments, EXIF, IPTC, etc.) from the JPEG file, achieving maximum metadata removal.
-o, --overwrite
Overwrite the source file with the optimized version (this is the default behavior).
-p, --preserve
Preserve the original file modification times after optimization.
-t, --threshold=size
Optimize only if the file size is reduced by at least the specified size (in kBytes).
-v, --verbose
Enable verbose output, showing detailed statistics for each processed file.
-q, --quiet
Enable quiet mode, suppressing most output messages.
-b, --bits=N
Force the file to N bits. Useful for converting to progressive JPEG by forcing 8-bit output.
-P, --preserve-perms
Preserve original file permissions after optimization.
-T, --csv
Output optimization statistics in CSV (Comma Separated Values) format.
-D, --pedantic
Do not ignore non-fatal errors during processing, leading to stricter error checking.
-X, --stdout
Output the optimized image to standard output (implies --noaction).
-S, --size=size
Try to optimize the file to a target size (e.g., '100K'). This may involve lossy compression.
-k, --keep-meta
Keep all metadata (EXIF, IPTC, comments, ICC profile) during optimization. Overrides stripping options.
--all-normal
Optimize all images to normal (baseline) JPEG/JFIF format.
--all-progressive
Optimize all images to progressive JPEG/JFIF format, which allows images to load gradually.
--all-lossless
Optimize all images losslessly (removes unneeded data without changing quality).
--strip-comments
Strip only JPEG comments.
--strip-exif
Strip only EXIF (Exchangeable Image File Format) markers.
--strip-iptc
Strip only IPTC (International Press Telecommunications Council) markers.
--strip-icc
Strip only ICC (International Color Consortium) profile.
--enable-gamma
Enable gamma correction during processing.
--disable-gamma
Disable gamma correction during processing.
--gamma-factor=factor
Set the gamma factor (default: 2.2).
--json
Output statistics in JSON format (implies --noaction).
--stdin
Read image data from standard input (implies --stdout and --noaction).
--use-arithmetic
Use arithmetic coding for JPEG compression (can sometimes yield smaller files but less widely supported).
--no-arithmetic
Do not use arithmetic coding (default is usually Huffman).
--disable-dqt
Disable DQT (Discrete Quantization Table) optimization.
--disable-cpi
Disable CPI (conditional progressive encoding) optimization.
--strip-jfif
Strip JFIF (JPEG File Interchange Format) header.
DESCRIPTION
jpegoptim is a command-line utility designed for optimizing and compressing JPEG image files. It can perform both lossless and lossy optimizations.
Lossless optimization removes unnecessary metadata (like comments, EXIF, IPTC, ICC profiles) and applies Huffman table optimization without altering image quality. Lossy optimization, on the other hand, allows you to reduce the image quality factor to achieve significantly smaller file sizes, though this comes at the cost of some image fidelity. The tool is highly efficient and useful for web developers, photographers, or anyone needing to reduce the file size of large collections of JPEG images for faster loading, reduced storage, or better email attachment sizes. It supports various options to control the compression level, metadata stripping, preservation of file attributes, and batch processing.
CAVEATS
- jpegoptim specifically works with JPEG files; it cannot process other image formats like PNG, GIF, or WebP.
- While lossless optimization is safe, using lossy compression (with
-m
or-S
) permanently reduces image quality to achieve smaller file sizes. Once quality is reduced, it cannot be fully recovered. - When optimizing a large number of files, it's advisable to test with
-n
(no action) first, or create backups before running the command to ensure desired results. - The effectiveness of jpegoptim might vary depending on the original JPEG file's quality and how it was saved. Heavily optimized JPEGs might see little further reduction.
BATCH PROCESSING
jpegoptim is particularly effective for batch processing directories full of JPEG images, often combined with commands like find or xargs to automate optimization tasks across many files.
LOSSLESS VS. LOSSY
Users should understand the distinction between lossless optimizations (which preserve visual quality by removing unneeded data) and lossy optimizations (which reduce quality for greater file size reduction), choosing the appropriate mode based on their needs.
HISTORY
jpegoptim was created by Simon Peter. It has been developed and maintained over the years as a reliable tool for optimizing JPEG images, often included in Linux distributions' official repositories. Its focus on efficiency and straightforward command-line usage has made it a popular choice for scripting and automated image processing workflows.