How to Optimize All Images for All Your Websites on the Same Server using Single Command?


We all know the images are the performance bottlenecks of pages loading. more than 60% of time is spent on downloading the images. Images can be optimized if you are willing to compromise some quality (most of the case, unnoticeable). JPEG/JPG can be optimized losslessly meaning that the original qualities of the images are not compromised. This is made possible by removing EXIF information, re-arrange the compression code e.g. Huffman.

At LINUX, you can install a simple open source JPEG optimizer, which is jpegoptim. The famous Image Compressor APIs are based on this tool as well. The jpegoptim can be used to shrink the images loselessly. To install that, you can run on Debian/Ubuntu:

1
sudo apt-get install jpegoptim
sudo apt-get install jpegoptim

Or if you are running RED hat, you can use yum install instead.

1
sudo yum install jpegoptim
sudo yum install jpegoptim

Then navigate to the root directory of all your websites or a particular domain on the single server, then running the following command should shrink all your JPEG images losslessly. The optimized images will overwrite the original images but this should be considered safe as it is the lossless compression.

find . ( -name "*.jpeg" -or -name "*.jpg" ) -exec jpegoptim --all-progressive --strip-all {} ; Click To Tweet

The parameter –all-progressive forces the JPEG to be progressive, if the sizes are smaller (use –force to convert to progressive JPEG even the file size after optimization is larger). It is said that the progressive JPEG on average has smaller file sizes for images larger than 10K.

You can specify the option -d directory if you decide to keep optimized images in a separate folders. To optimize PNG images, you can replace the above command using the optipng utility with slightly different parameters.

For jpegoptim you can specify the -m quality to conduct a lossy optimization.

optimize-images How to Optimize All Images for All Your Websites on the Same Server using Single Command? images jpeg linux ubuntu

optimize-images

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
431 words
Last Post: Posting SQL code on bbForum Triggers Security Rules by CloudFlare
Next Post: How to Tell Browsers Re-update CSS/JS files when Files are Changed in WordPress?

The Permanent URL is: How to Optimize All Images for All Your Websites on the Same Server using Single Command?

2 Comments

  1. Frank

Leave a Reply