gThumb – sending resized images by email

Post

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

  1. Tools -> Personalize…
  2. Create a new script
  3. Set name to “Send by email”
  4. Set command to “[path] %F” where [path] is the full path to the script
  5. Save

Sending images from gThumb

  1. Select images to be sent
  2. Tools -> Send by email