Jpegoptim is used to optimize/compress jpeg files. Program supports lossless optimization, which is based on optimizing the Huffman tables. And so called "lossy" optimization where in addition to optimizing Huffman tables user can specify upperlimit for image quality.
NOTE! By default jpegoptim modifies the input files (if they are optimized), to preserve original files use option
-d
to specify alternate directory for saving the optimized files to.
Only normal files are optimized (symbolic links and special files are skipped). Also, any other hard links to the file being optimized are unaf-fected.
Ubuntu:
$ [sudo] apt-get install jpegoptim
macOS with Homebrew:
$ brew install jpegoptim
An example of running jpegoptim recursively from the current directory. All images are compressed, with preserved permissions and modification times, progressive and with stripped (most of) metadata.
find . -type f -iname "*.jpg" -exec jpegoptim -p -P -m70 --strip-all --all-progressive {} \;
-p
Preserve file modification times.-P
Preserve file permissions (owner/group) by overwriting the original file.-m
Quality. Sets the maximum image quality factor 0 - 100.--all-progressive
Force all output files to be progressive.--strip-all
,-s
Strip all markers from output file.
The example was configured for a personal usage to have smaller file sizes with more or less good quality. Check help
$ man jpegoptim
for more parameters and their usage.