Posted 12/26/2013
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!
#!/bin/bash
pwd > ~/f0.txt
echo "$@" > ~/f1.txt
for file in $@
do
convert "$file" -quality 50 -resize 1024x768 "${file%/*}/web-${file##*/}"
done
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]
Type=Application
Version=1.0
Encoding=UTF-8
TryExec=scale-for-web
Exec=scale-for-web %F
Icon=
Name=Scale for the web
MimeType=image/jpeg;image/jpg;image/png
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 imageMagick, extract path segments, more details on string manipulation