-#!/bin/bash
+#!/bin/sh
## @file
## @brief Crop image
process_raw ()
{
- tmpdir=$(mktemp --tmpdir --directory geeqie_crop_image_XXXXXX)
+ tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
- list=$(exiv2 -pp "$1")
- if [[ ! -z "$list" ]]
- then
- readarray -t split_list <<<"$list"
+ array_length=$(exiv2 -pp "$1" | wc -l)
- array_length="${#split_list[@]}"
+ if [ "$array_length" -gt 0 ]
+ then
+ # Take last item - should be highest resolution
exiv2 --location "$tmpdir" -ep"$array_length" "$1"
src_filename=$(ls "$tmpdir/")
rotation=$(exiftool -Orientation -n "$1" | cut -d':' -f2 | xargs)
convert "$tmpdir/$src_filename" -crop "$2" "$tmpdir/$filename-crop.$extension"
- exiftool -Orientation=$rotation -n "$tmpdir/$filename-crop.$extension"
+ exiftool -Orientation="$rotation" -n "$tmpdir/$filename-crop.$extension"
rm "$tmpdir/$src_filename"
process_plain ()
{
- tmpdir=$(mktemp --tmpdir --directory geeqie_crop_image_XXXXXX)
+ tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
src_filename=$(basename -- "$1")
filename="${src_filename%.*}"
if [ -z "$coords" ]
then
- zenity --error --title="$title" --text="Rectangle coordinates have not been set" --width="$width" --window-icon="$window_icon" 2>/dev/null
+ zenity --error --title="$title" --text="Rectangle coordinates have not been set" --width="$width" --window-icon="$window_icon" 2> /dev/null
exit 0
fi
filename=$(basename -- "$1")
- extension="${filename##*.}"
-
- if [ "${extension,,}" = "jpeg" ]
+ extension=$(printf '%b' "${filename##*.}" | tr '[:upper:]' '[:lower:]')
+ if [ "${extension}" = "jpeg" ]
then
- source_file="$1"
- process_plain "$1" $coords
- elif [ "${extension,,}" = "jpg" ]
+ process_plain "$1" "$coords"
+ elif [ "${extension}" = "jpg" ]
then
- source_file="$1"
- process_plain "$1" $coords
- elif [ "${extension,,}" = "png" ]
+ process_plain "$1" "$coords"
+ elif [ "${extension}" = "png" ]
then
- source_file="$1"
- process_plain "$1" $coords
- elif [ "${extension,,}" = "tif" ]
+ process_plain "$1" "$coords"
+ elif [ "${extension}" = "tif" ]
then
- source_file="$1"
- process_plain "$1" $coords
- elif [ "${extension,,}" = "tiff" ]
+ process_plain "$1" "$coords"
+ elif [ "${extension}" = "tiff" ]
then
- source_file="$1"
- process_plain "$1" $coords
+ process_plain "$1" "$coords"
else
- process_raw "$1" $coords
+ process_raw "$1" "$coords"
if [ $? = 1 ]
then
- process_plain "$1" $coords
+ process_plain "$1" "$coords"
fi
fi
else
- zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nexiftool is not installed" --title="$title" --window-icon="$window_icon" 2>/dev/null
+ zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nexiftool is not installed" --title="$title" --window-icon="$window_icon" 2> /dev/null
exit 0
fi
else
- zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nImageMagick is not installed" --title="$title" --window-icon="$window_icon" 2>/dev/null
+ zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nImageMagick is not installed" --title="$title" --window-icon="$window_icon" 2> /dev/null
exit 0
fi
+