Ubuntu / Linux news and application reviews.

WebUpd8 reader Bruce Ingalls has created a script for batch lossy compression of jpg and png files. The script is useful if you have a lot of images - e.g., you can run it to compress all the images used by a website, etc.

The script compresses only the files for which the resulted compressed image is detected to be smaller than the original image file. It uses GraphicsMagick which Bruce says is better for compression than ImageMagick (~1.5% smaller images with GraphicsMagick than with ImageMagick) and also faster, when compressing a large number of images.

Also, the script doesn't overwrite the original files and instead, it places the compressed images under a folder called "compressed". You can configure the compressed directory path/name, the compression ratio (40 by default) and the png compression ratio of transparent background (05 by default) by editing the script.

GraphicsMagick cannot handle gif files, so it converts such files to png.

The compressLossy script doesn't do magick so don't expect png files to be a lot smaller after compression (the compression should be more obvious for jpg files). But it makes a difference if you're compressing a large amount of files.

image compression result mc

Download compressLossy

You can download the compressLossy script from GitHub - here's a direct link to the script (tip: Bruce's GitHub repository also has a script called "apple-touch.sh" which generates Apple iPad/iPhone favicons).

To be able to use the compressLossy script, install GraphicsMagick - in Ubuntu, use the following command:
sudo apt-get install graphicsmagick

Then, place the script in a folder containing png/jpg files, make the script executable and run it.

thanks to Bruce Ingalls for the script and info!