Saturday, June 2, 2012

Thunar Custom Actions: Resize and Rotate Images with Convert

Here I'm posting two simple bash scripts I use along with Thunar Custom Actions to resize and rotate images. Both of them work for on or more selected files.
Rotated images will be changed in place, resizing images will keep the original file and prepend "resized_to_<percent>" to the resized image, where <percent> indicates the selected reduction percent applied.

resize script:
     1  #!/bin/bash
     3  PERCENT="$1"
     4    shift
     5  while (( "$#" )); do  
     6    convert "$1" -resize "$PERCENT%" -quality 100 "resized_to_${PERCENT}%_$1"
     7    shift
     8  done
    10  exit 0

rotate script:
     1  #!/bin/bash
     4  DIRECTION="$1"
     5  shift
     7  case "$DIRECTION" in
     8    "r")
     9      while (( "$#" )); do
    10        convert -rotate 90 -quality 100 "$1" "$1" 
    11        shift
    12      done
    13    ;;
    14    "l")
    15      while (( "$#" )); do
    16        convert -rotate -90 -quality 100 "$1" "$1"
    17        shift
    18      done
    19    ;;
    20  esac
    22  exit 0

Adding Custom Actions

Take a look at this thunar wiki article it describes how to add custom actions to Thunar.
The resize script will need the desired resizing percent as an argument.
The rotate script needs the desired rotate direction (l or r), it always rotates in 90° steps.


  1. Seems the resize script doesn't work on my Xubuntu 13.04

    1. The script depends on "convert" which should be included in the imagemagick package.
      You can install imagemagick under ubuntu (and derivatives like Xubuntu) by opening a terminal and
      typing the following command:

      $ sudo apt-get install imagemagick

      Please note that the $ character is the promp symbol. It is not part of the command.

      Take a look at this link
      for further information about imagemagick under ubuntu:

      Take also a look at this article to properly install the custom action in tunar.

  2. Thanks for this! Found via google and used your idea but modified the script to use graphicsmagick (fork of imagemagick) instead due to smaller install needed (no dependencies or un-needed gui)