Drag-n-drop “save for web” linux script for images

The other tools

Photoshop has a great “save for web” command to batch optimize pictures with a few clicks. In linux world I wasn’t able to find such a powerful gui program for batch optimization. The alternatives were Gimp “save for web” plugin, but lacks batching for that specific functionality. Phatch is a very good graphical solution for batch scaling, transforming etc, but the final result wasn’t what i expected. The picture size had not been minimized enough. ImageMagick is a powerfull tool for the job, but no GUI…

The “save for web” script

After being tired searching the web for a fast and simple solution, I decided to get my hands dirty with imageMagick, create bash scripts and give them an impression of graphical interface. Now, I just drag and drop all the images in a folder, I double click the bash script that is inside that folder, and a new folder is created with all the images copied, resized, scaled down to 800×600 (if the original is less, it is left untouched) and optimized at 72 dpi. Script created and tested on Ubuntu 14.04. Also, notice that imageMagick and jpegoptim tools must be installed on your system.

########################################################
#!/bin/bash
mkdir optimised
#optimise jpg
for i in *.jpg *.JPG .jpeg; do jpegoptim --max=85  --strip-all --all-progressive --dest=optimised -o --totals "$i"; done

#reduce to 800 or 600 px -if it is bigger, to 72 dpi
#keep the same names
for i in optimised/*.jpg optimised/*.JPG optimised/*.jpeg; \
    do  convert  -resize 800x600\> \
                -density 72 \
                $i $i; done

########################################################
#!/bin/bash
# convert png (even transparent) to jpg
mogrify -format jpg -background black -flatten *.png

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
TOC
Scroll to Top