1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#!/bin/sh
## @file
## @brief Crop image
##
## Requires ImageMagick and exiftool
## Crops the image to the size set by the Draw Rectangle menu item
##
process_raw ()
{
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
array_length=$(exiv2 -pp "$1" | wc -l)
if [ "$array_length" -gt 0 ]
then
# Take last item - should be highest resolution
exiv2 --location "$tmpdir" -ep"$array_length" "$1"
src_filename=$(ls "$tmpdir/")
filename="${src_filename%.*}"
extension="${src_filename##*.}"
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"
rm "$tmpdir/$src_filename"
geeqie --remote --view="$tmpdir/$filename-crop.$extension"
res=0
else
res=1
fi
return "$res"
}
process_plain ()
{
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
src_filename=$(basename -- "$1")
filename="${src_filename%.*}"
extension="${src_filename##*.}"
convert "$1" -crop "$2" "$tmpdir/$filename-crop.$extension"
if [ $? = 1 ]
then
zenity --error --title="$title" --text="Cannot process this file format" --width="$width" --window-icon="$window_icon"
else
geeqie --remote --view="$tmpdir/$filename-crop.$extension"
fi
}
export window_icon="/usr/local/share/pixmaps/geeqie.png"
export title="Geeqie crop image"
export width="250"
if [ -x "$(command -v convert)" ]
then
if [ -x "$(command -v exiftool)" ]
then
coords=$(geeqie --remote --get-rectangle)
if [ -z "$coords" ]
then
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=$(printf '%b' "${filename##*.}" | tr '[:upper:]' '[:lower:]')
if [ "${extension}" = "jpeg" ]
then
process_plain "$1" "$coords"
elif [ "${extension}" = "jpg" ]
then
process_plain "$1" "$coords"
elif [ "${extension}" = "png" ]
then
process_plain "$1" "$coords"
elif [ "${extension}" = "tif" ]
then
process_plain "$1" "$coords"
elif [ "${extension}" = "tiff" ]
then
process_plain "$1" "$coords"
else
process_raw "$1" "$coords"
if [ $? = 1 ]
then
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
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
exit 0
fi
|