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.
1 |
$ sudo apt-get update |
1 |
$ sudo apt-get install jpegoptim |
You can check if the installation is successful by running command below to check the version.
1 |
$ jpegoptim --version |
Centos
Run the command below to update the package list and install jpegoptim on Centos.
1 |
yum install jpegoptim |
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:
1 |
yum repolist enabled |
If you don’t see the epel repo in the list, try the command below to enable it.
1 |
yum-config-manager --enable epel |
or install it
1 |
yum install epel-release |
Now let’s see some common use cases below:
Losslessly Compress a Single Image
1 |
jpegoptim filename.jpg |
Compress Quality to 80% for all Images in a Folder
1 |
find . -type f -name "*.jpg" | xargs jpegoptim --max=80 -f --strip-all |
Compress Quality to 60% for all Images in a Folder That are larger than 500kb
1 |
find . -size +500k -type f -name "*.jpg" | xargs jpegoptim --max=60 -f --strip-all |
If you will need a detailed user manual, here is a link https://www.systutorials.com/docs/linux/man/1-jpegoptim/