How to Optimize Images Online in Linux?

January 15, 2015 / FAQs
linux

Online image optimization in Linux:

Image compression may have an interest in many situations. For example, while writing a web article in which we need compressed images to reduce the total weight of a web page. Image compression may also need while sending an email. For this, it is worthwhile to know how to do it quickly from the command line. So here we will see how to lighten images in PNG, JPEG/JPG format with various tools.

PNG images optimization with pngcrush

First, we need to install pngcrush, in Debian we will use the below command:

apt-get install pngcrush

For CentOS and RHEL, use this syntax:

yum install pngcrush

Once installed, pngcrush is very easy to use, for example:

pngcrush -brute -e "compressedimage.png" image_original.png

Here, “-brute” allows us better optimization of the image, “-e” compresses the original image (Note: after specifying “-e” mention the name for the compressed image which will be the output of the tool).

JPEG image optimization with jpegoptim

As similar to pngcrush first we need to install jpegoptim tool. The execution command for Debian:

apt-get install jpegoptim

For CentOS and RHEL machines:

yum install jpegoptim

To use jpegoptim and optimize an image, we simply need to run the following command line:

jpegoptim myimage.jpeg

We can also change the power of the compression with the option “-m” followed by a number from 1 to 100 range. 1 will give a very light image, but with very poor quality. 100 will give a smaller compression but maintains certain quality. So we are the judge to decide what value to put in! Generally, 80 is a good ratio between lightness and image quality.

jpegoptim myimage.jpeg -m 80