From dffb94e1a77d0b0450f7de44e63c690a15b488b6 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sat, 27 Oct 2018 12:40:59 +0100 Subject: [PATCH] Plugin for image crop Requires ImageMagick and exiftool --- configure.in | 1 + plugins/Makefile.am | 2 +- plugins/image-crop/Makefile.am | 9 ++ plugins/image-crop/geeqie-image-crop | 109 +++++++++++++++++++++++ plugins/image-crop/image-crop.desktop | 17 ++++ plugins/image-crop/image-crop.desktop.in | 17 ++++ po/POTFILES.in | 1 + 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 plugins/image-crop/Makefile.am create mode 100644 plugins/image-crop/geeqie-image-crop create mode 100644 plugins/image-crop/image-crop.desktop create mode 100644 plugins/image-crop/image-crop.desktop.in diff --git a/configure.in b/configure.in index f891a588..bcb40be8 100644 --- a/configure.in +++ b/configure.in @@ -622,6 +622,7 @@ AC_CONFIG_FILES([ plugins/export-jpeg/Makefile plugins/tethered-photography/Makefile plugins/camera-import/Makefile + plugins/image-crop/Makefile geeqie.spec ]) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 5df6aca7..929d7dd9 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -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 diff --git a/plugins/image-crop/Makefile.am b/plugins/image-crop/Makefile.am new file mode 100644 index 00000000..809260c0 --- /dev/null +++ b/plugins/image-crop/Makefile.am @@ -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) diff --git a/plugins/image-crop/geeqie-image-crop b/plugins/image-crop/geeqie-image-crop new file mode 100644 index 00000000..09482ee1 --- /dev/null +++ b/plugins/image-crop/geeqie-image-crop @@ -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 diff --git a/plugins/image-crop/image-crop.desktop b/plugins/image-crop/image-crop.desktop new file mode 100644 index 00000000..7501e92a --- /dev/null +++ b/plugins/image-crop/image-crop.desktop @@ -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 diff --git a/plugins/image-crop/image-crop.desktop.in b/plugins/image-crop/image-crop.desktop.in new file mode 100644 index 00000000..82d3ce9d --- /dev/null +++ b/plugins/image-crop/image-crop.desktop.in @@ -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 diff --git a/po/POTFILES.in b/po/POTFILES.in index 9ee74c27..74ecb06e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,6 +4,7 @@ plugins/import/geeqie-import-gqview.desktop.in 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 -- 2.20.1