Mercurial > hg > forks > geeqie
changeset 2858:4c7dd47bbcd6
Plugin for image crop
Requires ImageMagick and exiftool
author | Colin Clark <colin.clark@cclark.uk> |
---|---|
date | Sat, 27 Oct 2018 12:40:59 +0100 |
parents | da1b564a4eeb |
children | 1656d2341e2f |
files | configure.in plugins/Makefile.am plugins/image-crop/Makefile.am plugins/image-crop/geeqie-image-crop plugins/image-crop/image-crop.desktop plugins/image-crop/image-crop.desktop.in po/POTFILES.in |
diffstat | 7 files changed, 155 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in Thu Oct 25 20:11:22 2018 +0100 +++ b/configure.in Sat Oct 27 12:40:59 2018 +0100 @@ -622,6 +622,7 @@ plugins/export-jpeg/Makefile plugins/tethered-photography/Makefile plugins/camera-import/Makefile + plugins/image-crop/Makefile geeqie.spec ])
--- a/plugins/Makefile.am Thu Oct 25 20:11:22 2018 +0100 +++ b/plugins/Makefile.am Sat Oct 27 12:40:59 2018 +0100 @@ -1,6 +1,6 @@ #FIXME enable or disable individual plugins from configure -SUBDIRS = rotate symlink ufraw import geocode-parameters export-jpeg tethered-photography camera-import +SUBDIRS = rotate symlink ufraw import geocode-parameters export-jpeg tethered-photography camera-import image-crop qq_desktoptemplatedir = $(appdir) qq_desktoptemplate_DATA = template.desktop
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/image-crop/Makefile.am Sat Oct 27 12:40:59 2018 +0100 @@ -0,0 +1,9 @@ +dist_gq_bin_SCRIPTS = geeqie-image-crop + +gq_desktopdir = $(appdir)/applications +gq_desktop_in_files = image-crop.desktop.in +gq_desktop_DATA = $(gq_desktop_in_files:.desktop.in=.desktop) +@INTLTOOL_DESKTOP_RULE@ + +EXTRA_DIST = $(gq_desktop_in_files) +CLEANFILES = $(gq_desktop_DATA)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/image-crop/geeqie-image-crop Sat Oct 27 12:40:59 2018 +0100 @@ -0,0 +1,109 @@ +#!/bin/bash + +# Crop image +# +# Requires ImageMagick and exiftool + + +process_raw () +{ + tmpdir=$(mktemp --tmpdir --directory geeqie_crop_image_XXXXXX) + + list=$(exiv2 -pp "$1") + if [[ ! -z "$list" ]] + then + readarray -t split_list <<<"$list" + + array_length="${#split_list[@]}" + exiv2 -ep"$array_length" "$1" --location "$tmpdir" + + 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 --tmpdir --directory geeqie_crop_image_XXXXXX) + + 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="${filename##*.}" + + if [ "${extension,,}" = "jpeg" ] + then + source_file="$1" + process_plain "$1" $coords + elif [ "${extension,,}" = "jpg" ] + then + source_file="$1" + process_plain "$1" $coords + elif [ "${extension,,}" = "png" ] + then + source_file="$1" + process_plain "$1" $coords + elif [ "${extension,,}" = "tif" ] + then + source_file="$1" + process_plain "$1" $coords + elif [ "${extension,,}" = "tiff" ] + then + source_file="$1" + 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/image-crop/image-crop.desktop Sat Oct 27 12:40:59 2018 +0100 @@ -0,0 +1,17 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Image crop + +# Requires ImageMagick and exiftools + +Exec=geeqie-image-crop %f + +# Desktop files that are usable only in Geeqie should be marked like this: +Categories=X-Geeqie; +OnlyShowIn=X-Geeqie; + +# It can be made verbose +#X-Geeqie-Verbose=true + +Icon=geeqie
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/image-crop/image-crop.desktop.in Sat Oct 27 12:40:59 2018 +0100 @@ -0,0 +1,17 @@ +[Desktop Entry] +Version=1.0 +Type=Application +_Name=Image crop + +# Requires ImageMagick and exiftools + +Exec=geeqie-image-crop %f + +# Desktop files that are usable only in Geeqie should be marked like this: +Categories=X-Geeqie; +OnlyShowIn=X-Geeqie; + +# It can be made verbose +#X-Geeqie-Verbose=true + +Icon=geeqie
--- a/po/POTFILES.in Thu Oct 25 20:11:22 2018 +0100 +++ b/po/POTFILES.in Sat Oct 27 12:40:59 2018 +0100 @@ -4,6 +4,7 @@ plugins/export-jpeg/export-jpeg.desktop.in plugins/tethered-photography/tethered-photography.desktop.in plugins/camera-import/camera-import.desktop.in +plugins/image-crop/image-crop.desktop.in plugins/rotate/rotate.desktop.in plugins/symlink/symlink.desktop.in plugins/ufraw/geeqie-ufraw.desktop.in