Easily scaling images for the web

Posted 12/26/2013

Scaling images for the web—easily and quickly

Starting Gimp just to scale down some photos to send them by mail? Meh. How about mark them, right-click, “Send To” -> “Scale for web”? That would be nice. Let’s code it!

First, get a tool to scale images:

sudo apt-get install imagemagick

Now, create a script that takes a list of images as input, scales them down, and stores them with a prefixed file name. Go!

pwd > ~/f0.txt
echo "$@" > ~/f1.txt
for file in $@
    convert "$file" -quality 50 -resize 1024x768 "${file%/*}/web-${file##*/}"

Make sure to chmod +x the script file we just created. Next, let’s integrate it into “Send To”. This is an example for Thunar on XFCE. Create a .desktop file in the sendto folder, e.g. /usr/share/Thunar/sendto/scale-for-web.desktop with following content:

# Scale images for the web
[Desktop Entry]
Exec=scale-for-web %F
Name=Scale for the web

Replace both scale-for-web with the name you gave to your script file. Is the script’s folder in $PATH? No idea? Then just put the entire path+filename.

Now, open Thunar, select some images (Jpeg or Png), right-click, “Send To” -> “Scale for the web”, wait a few seconds and you’ll see web-....jpg files appearing in the same folder. 🙂

Archived references: how to scale images with imageMagickextract path segmentsmore details on string manipulation