Scale images for the web — quickly

Start­ing Gimp just to scale down some pho­tos to send them by mail? Meh.
How about mark them, right-click, “Send To” -> “Scale for web”?
No prob­le­mo:
First, get a tool to scale images: 

sudo apt-get install imagemagick

Now, cre­ate a script that takes a list of images as input, scales them down, and stores them with a pre­fixed file name. Go!

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

Make sure we chmod +x the script file we just cre­at­ed.
Next, let’s inte­grate it into “Send To”. (This is an exam­ple for Thu­nar)
Cre­ate a .desktop file in the sendto fold­er, e.g. /usr/share/Thunar/sendto/scale-for-web.desktop with fol­low­ing con­tent:

# 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 fold­er in $PATH? No idea? Then just put the entire path+filename.
Now, open Thu­nar, select some images (Jpeg or Png), right-click, “Send To” -> “Scale for the web”, wait a few sec­onds and you’ll see web-....jpg files appear­ing in the same fold­er. 🙂

Ref­er­ences: how to scale images with imageMag­ick, extract path seg­ments, more details on string manip­u­la­tion

Leave a Reply

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