gThumb is a great image viewer but while it offers several ways of sharing images (Flickr, Facebook, etc.), sharing by email is not one of them. Fortunately, it offers a way to call a custom script on selected images.
The following is a sample script to send resized images using Thunderbird. To make it more universal (e.g. resizing using different tools if ImageMagick is not installed, sending via different email clients) would require further work and more complexity. Therefore, take it only as a starting point for your own script.
Dependencies
- ImageMagick (convert) - for resizing of images.
- Thunderbird - for sending emails.
- wmctrl - for focusing mail compose window.
Script
#!/bin/bash
# New image dimensions
maxwidth=800
maxheight=600
# Create a temporary directory
directory="/tmp/gThumb-$(date +%s)"
if [ ! -d "$directory" ]; then
mkdir "$directory"
fi
# Resize the images
files=()
x=0
for i in "$@"; do
if [ -f "$i" ]; then
filename=`basename "$i"`
filepath="$directory/$filename"
convert "$i" +profile '*' -auto-orient -quality 90 -resize "${maxwidth}x${maxheight}>" -adaptive-sharpen 0x0.8 "$filepath"
files[$x]=$filepath
((x+=1))
fi
done
# Create a string of files to be used during mail invocation
filestring=''
for i in "${files[@]}"; do
if [ "$filestring" == "" ]; then
filestring="$i"
else
filestring="$filestring,$i"
fi
done
# Send the images using Thunderbird
if [ "$filestring" != "" ]; then
thunderbird -compose "attachment='$filestring'"
wmctrl -a "$(wmctrl -l | grep Thunderbird | cut -f 1,2,3,4 -d ' ' --complement)"
fi
exit 0
Setting up gThumb
- Tools -> Personalize…
- Create a new script
- Set name to “Send by email”
- Set command to “[path] %F” where [path] is the full path to the script
- Save
Sending images from gThumb
- Select images to be sent
- Tools -> Send by email