How to Compress Images with Jpegoptim

Jpegoptim is a utility to optimize/compress JPEG files. You can compress JPG format image losslessly with it, or you can set a maximum quality factor to compress the images into even smaller files.

Install Jpegoptim in Ubuntu or CentOS

Ubuntu

Run the commands below to update the package list and install jpegoptim on Ubuntu.

You can check if the installation is successful by running command below to check the version.

Centos

Run the command below to update the package list and install jpegoptim on Centos.

If you are running into an error saying “no package available”, make sure you have repo epel installed and enabled because jpegoptim is a part of epel on Centos.
You can use the command below to list all the enabled repos:

If you don’t see the epel repo in the list, try the command below to enable it.

or install it

Now let’s see some common use cases below:

Losslessly Compress a Single Image

Compress Quality to 80% for all Images in a Folder

Compress Quality to 60% for all Images in a Folder That are larger than 500kb

If you will need a detailed user manual, here is a link https://www.systutorials.com/docs/linux/man/1-jpegoptim/