Skip to content
Latchkey

jpegoptim: Optimize JPEG Files in CI

jpegoptim --strip-all --max=85 image.jpg re-optimizes a JPEG to at most quality 85 and removes its metadata, in place.

jpegoptim shrinks JPEGs either losslessly (re-optimize Huffman tables) or lossily (cap quality / hit a target size). It edits in place, so the quality and strip flags matter most.

What it does

jpegoptim recompresses JPEG files. With no quality flag it is lossless (optimizes coding only). --max=<q> caps quality (lossy, only re-encodes if it helps); --size=<n> targets a byte/percent size. --strip-all removes EXIF/comment/ICC markers.

Common usage

Terminal
# lossless optimize + strip metadata, in place
jpegoptim --strip-all image.jpg
# cap quality at 85
jpegoptim --strip-all --max=85 image.jpg
# target ~200 KB
jpegoptim --size=200k image.jpg
# write optimized copies into another dir
jpegoptim --strip-all --dest=out *.jpg

Options

FlagWhat it does
--max=<q>Maximum quality 0-100 (lossy cap)
--size=<n>Target size, e.g. 200k or 30% (lossy)
--strip-allRemove all markers (EXIF, comments, ICC)
--strip-exifRemove only EXIF data
--dest=<dir>Write to a directory instead of in place
-m / --all-progressiveForce progressive output (-m sets max)

In CI

jpegoptim overwrites the input by default; use --dest to keep originals, or run it on build artifacts. It prints "skipped" when it cannot shrink a file further, which is normal and exits 0. Combine --strip-all with a --max to get both metadata removal and size savings.

Common errors in CI

"jpegoptim: command not found" means install jpegoptim. "image.jpg is not a JPEG file!" means a PNG/other format was passed (jpegoptim is JPEG-only). A file that comes back the same size with "skipped" output is already optimal, not an error. "Can't open ... for writing" means the file or directory is read-only; write to a writable path or --dest.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →