All posts
Compress JPEG via CLI
Lossless: jpegtran optimizes Huffman tables and strips EXIF.
Open online converterPackages to install
libjpeg-turbo-progs provides jpegtran, a lossless JPEG optimizer.
libjpeg-turbo-progs
sudo apt-get update
sudo apt-get install -y libjpeg-turbo-progsHow to run the command
jpegtran -copy none strips metadata, -optimize rebuilds Huffman tables, and -outfile writes the result. Pixels are not re-encoded.
jpegtran -copy none -optimize -outfile photo.min.jpg photo.jpgDockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libjpeg-turbo-progs && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t compress-jpg .
docker run --rm -v "$PWD:/work" -w /work compress-jpg \
jpegtran -copy none -optimize -outfile photo.min.jpg photo.jpgExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
jpegtran -copy none -optimize -outfile photo.min.jpg photo.jpgjpegtran -copy none -optimize -progressive -outfile photo.min.jpg photo.jpg