JPEGOptim is a server side tool that can batch compress all files within a website, web application or the entire server.
You will need to install: epel-release via our server’s package manager.
For Centos/RHL: yum install jpegoptim
Ubuntu/Debian: apt-get install jpegoptim
We typically will combine this with the find command to selectively find all files, strip out the META and other superfluous information and compress them down to a reasonable high-enough quality value (60).
find . -type f -name "*.jpg" | xargs jpegoptim --max=60 -f --strip-all
You can also install OptiPNG and use a similar command:
find . -type f -iname "*.png" -print0 | xargs -I {} -0 optipng -o5 -quiet -keep -preserve -log optipng.log "{}"
Here are some additional examples of JPEGoptim syntax that we commonly use:
- Optimize a single JPEG image:
jpegoptim image.jpg
This command optimizes the image.jpg file and replaces the original file with the optimized one. By default, JPEGoptim uses a compression level of 75, but you can adjust it using the -m option followed by a compression level between 0 and 100, where 0 means no compression and 100 means maximum compression.
- Optimize multiple JPEG images:
jpegoptim image1.jpg image2.jpg image3.jpg
This command optimizes multiple JPEG images and replaces the original files with the optimized ones. You can also use wildcards to optimize all JPEG images in a directory, like this:
jpegoptim *.jpg
- Optimize JPEG images recursively:
jpegoptim -r /path/to/images
This command recursively optimizes all JPEG images in the /path/to/images directory and its subdirectories.
- Show optimization statistics:
jpegoptim -v image.jpg
This command shows the optimization statistics for the image.jpg file, including the original size, the optimized size, and the compression percentage.
- Strip EXIF data:
jpegoptim --strip-all image.jpg
This command strips all EXIF data from the image.jpg file, which can significantly reduce the file size. You can also choose to strip only some specific EXIF tags using the –strip-exif option followed by a comma-separated list of tags to strip.
- Set a maximum file size:
jpegoptim --size=100k image.jpg
This command optimizes the image.jpg file and tries to reduce its size to a maximum of 100 kilobytes. If the optimization process cannot achieve this size, it will use the best compression level possible.
These are some examples of JPEGoptim syntax that you can use to optimize JPEG images. You can find more options and parameters in the JPEGoptim documentation.




