Plugin for image crop
authorColin Clark <colin.clark@cclark.uk>
Sat, 27 Oct 2018 11:40:59 +0000 (12:40 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sat, 27 Oct 2018 11:40:59 +0000 (12:40 +0100)
Requires ImageMagick and exiftool

configure.in
plugins/Makefile.am
plugins/image-crop/Makefile.am [new file with mode: 0644]
plugins/image-crop/geeqie-image-crop [new file with mode: 0644]
plugins/image-crop/image-crop.desktop [new file with mode: 0644]
plugins/image-crop/image-crop.desktop.in [new file with mode: 0644]
po/POTFILES.in

index f891a58..bcb40be 100644 (file)
@@ -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
 ])
 
index 5df6aca..929d7dd 100644 (file)
@@ -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 (file)
index 0000000..809260c
--- /dev/null
@@ -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 (file)
index 0000000..09482ee
--- /dev/null
@@ -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 (file)
index 0000000..7501e92
--- /dev/null
@@ -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 (file)
index 0000000..82d3ce9
--- /dev/null
@@ -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
index 9ee74c2..74ecb06 100644 (file)
@@ -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