Note: Here we have used a JPG format image however both the JPEG and JPG are the same. This tool can convert any of them.
How to Install jpegoptim on Linux
To install the jpegoptim tool run the following command:
We have a test image with a size of 3.1MB. Now we will compress this image using the jpegoptim tool.
We can also check image size using the list command:
Compressing Image Using jpegoptim to an Optimize Value
To compress the image run following command:
Here we can see the image is compressed slightly by 0.23%. This is auto compression by jpegoptim tool.
However, we can also define the size at which we want to compress the image.
Compressing Image to a Specific Size
Run the below command to compress the image from 3mb to approximately 1mb file. You can also define a custom file size.
Terminal shows image size reduced from 3mb to 1mb.
Compressing and Save Image to a Specific Destination
To compress image to a specific destination run given command:
This command will reduce image size to approximately 800 kb and save the file on Desktop.
To confirm the image conversion, we can list the Desktop files:
Optimizing Several Images at a Time
To optimize multiple images all at once run the given command:
Batch Process an Entire Folder of Images
To batch process an entire folder of jpg images run the command:
To find further information and full list of option about jpegoptim tool run the given command:
Conclusion
The JPEG compression in Linux can be done using the jpegoptim tool in the terminal. This provides a convenient and efficient way to optimize JPEG images for web usage, reducing file size while maintaining image quality.