Category: convert

Thunar, a custom action to resize pictures

Nautilus has the handy feature to resize or rotate pictures directly with the right button. Unfortunately Thunar lacks of this feature but with a custom action we can get almost the same.

First of all install the utilities which execute the conversion and show the resize dialog

sudo apt-get install imagemagick zenity

Then create a script named picture_resize.sh inside the Thunar folder settings

mkdir ~/.config/Thunar/custom_actions
touch ~/.config/Thunar/custom_actions/picture_resize.sh

Edit the file as follow

#!/bin/bash

# Title   : Thunar Custom Action to resize a picture
# Author  : Cesare Riva
# Version : 1.0
# Date    : 17-03-2016   

DEST="./resized"
WIDTH=140
HEIGHT=190 
QUALITY=75


# check required software
CHECK=("convert" "zenity")
for i in "${CHECK[@]}"
do
  if ! command -v $i >/dev/null 2>&1 ; then
      echo "Error: '$i' not found (install the appropriate package)" 1>&2
      exit 1
  fi
done

resize=$(zenity --width=$WIDTH --height=$HEIGHT --list \
  --text "Choose resize level" --radiolist  --column "%" --column "Resize"\
  FALSE 25 TRUE 50 FALSE 75);

# check if "Cancel" button
if ! [[ $resize ]];
then
  exit 1
fi

mkdir -p $DEST

for file
    do
    if [ ! -e $file ]
        then
        continue
    fi
    to_name="$DEST/"$(echo $file | cut -f1 -d.)".jpg"
    convert -resize $resize% -quality $QUALITY "${file}" "${to_name}"
done

exit 0

Quite self explaining, a dialog appears to choose the resize level (values: 25%, 50%, 75%), then in the working directory is created the resized folder in which each pictures is put resized and converted to .jpg.

Make it executable

chmod +x ~/.config/Thunar/custom_actions/picture_resize.sh

Open Thunar and select Edit => Configure custom actions… and edit as shown, the path to the script is

/home/cesare/.config/Thunar/custom_actions/picture_resize.sh %N

 

 

In the tab Appearance Conditions select only Image Files and File Pattern: *

You should have something like this now.

 

Now you can select one or more pictures and find them in /resized

 

 

 

How to convert a .pdf to .jpg

Assuming imagemagick is already installed, simply:

$ convert -density 300 document.pdf image.jpg

where density is the output resolution in dpi, default is 72 but when converting a document to an image better to set it at 300 for a good quality.
There is a huge list of options here.

WordPress Themes