[gimp-help-2: 3/7] [make] Add target for checking image file resolutions



commit 1ffc9df0bb84c9420464222871e800a3cf5f9c1c
Author: Ulf-D. Ehlert <ulfehlert svn gnome org>
Date:   Thu Aug 13 10:52:51 2009 +0200

    [make] Add target for checking image file resolutions
    
    'make check-image-resolutions-LANG' will find image files in
    images/LANG with print resolution != 144x144 dpi.

 Makefile.GNU                     |    6 +++-
 Makefile.am                      |    6 +++-
 tools/README                     |   17 +++++++++-
 tools/check_image_resolutions.sh |   65 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 4 deletions(-)
---
diff --git a/Makefile.GNU b/Makefile.GNU
index d239bb7..6e80a52 100644
--- a/Makefile.GNU
+++ b/Makefile.GNU
@@ -773,10 +773,14 @@ check-images-%: FORCE
 	$(cmd) $(RMAKE) check-image-references \
 		VALIDATEREFERENCESFLAGS="--imgdir=images/C,images/$*"
 
+check-image-resolutions-%:
+	$(cmd) /bin/sh tools/check_image_resolutions.sh images/$*
+
 # special case 'en':
 check-images-en check-images-C: check-image-references ;
+check-image-resolutions-en: check-image-resolutions-C ;
 
-.PHONY: check-image-references
+.PHONY: checks check-image-references check-image-resolutions-%
 
 
 ########################################################################
diff --git a/Makefile.am b/Makefile.am
index 06ea3c5..4d9825e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -812,10 +812,14 @@ check-images-%: FORCE
 	$(cmd) $(RMAKE) check-image-references \
 		VALIDATEREFERENCESFLAGS="--imgdir=images/C,images/$*"
 
+check-image-resolutions-%:
+	$(cmd) /bin/sh tools/check_image_resolutions.sh images/$*
+
 # special case 'en':
 check-images-en check-images-C: check-image-references ;
+check-image-resolutions-en: check-image-resolutions-C ;
 
-.PHONY: checks check-image-references
+.PHONY: checks check-image-references check-image-resolutions-%
 
 
 if HAVE_DOT
diff --git a/tools/README b/tools/README
index a84fba5..c1938db 100644
--- a/tools/README
+++ b/tools/README
@@ -213,16 +213,29 @@ Usage:
 
         tools/get_po_status.pl [options] po-directory
 
-Options:    
+Options:
         --[no]files       [Don't] print file statistics
         --[no]summary     [Don't] print summary
         --[no]progress    [Don't] print "progress" bar
         --todo            Only print files with untranslated messages
         --lang LANG       Add language "LANG" for naming the progress bar
-    
+
 Use "perldoc tools/get_po_status.pl" for more information.
 
 
+check_image_resolutions.sh
+==========================
+
+A simple shell script to find images with resolution != 144x144 dpi.
+
+Requirements:
+    - identify (from the ImageMagick package: http://www.imagemagick.org)
+    - awk
+
+Usage:
+    tools/check_image_resolutions.sh DIR [DIR ...]
+
+
 check_keywords_property.pl
 ==========================
 
diff --git a/tools/check_image_resolutions.sh b/tools/check_image_resolutions.sh
new file mode 100755
index 0000000..76bd353
--- /dev/null
+++ b/tools/check_image_resolutions.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+#
+# check_image_resolutions -- find image files with resolution != 144x144 dpi
+# Copyright (C) 2009 The GIMP Documentation Team.
+# License: GPL
+#
+
+usage="Usage: ${0##*/} DIR [DIR ...]"
+programs="find xargs identify awk"
+
+die() {
+    exitcode="$1"; shift
+    echo >&2 "$*"
+    exit $exitcode
+}
+
+# Check command line arguments
+if [ -n "$1" ]; then
+    for arg; do
+        test -d "$arg" || die 65 "No such directory: $arg"
+    done
+else
+    die 64 "$usage"
+fi
+
+# Check for required programs
+for prog in $programs; do
+    type $prog >/dev/null 2>&1 || die 69 "Missing program: $prog"
+done
+
+# Start
+find "$@" -name .git -prune \
+          -o \( -name *.png -o -name *.jpg \) -print | \
+xargs identify -format "%d/%f %x %y %wx%h\n" | \
+sort | \
+awk '
+    BEGIN {
+        n = 0; m = 0;
+        c[0]="|"; c[1]="/"; c[2]="-"; c[3]="\\";
+        print("Checking image files for potential resolution problems...");
+    }
+    # Input:
+    #     $1  -  file name (incl. path)
+    #     $2  -  x resolution (ok: 56.69, 56.70, 143.*, 144.*)
+    #     $3  -  x units (e.g. "PixelsPerInch", "Undefined", ...)
+    #     $4  -  y resolution
+    #     $5  -  y units
+    #     $6  -  <width>x<height>
+    # Example:
+    #     path/to/image.png 56.69 PixelsPerCentimeter \
+    #         56.69 PixelsPerCentimeter 273x303
+    /./ { ++n }
+    /./ && ($2 !~ /^(56\.|14[34])/ || $4 !~ /^(56|14[34])/) {
+        ++m;
+        if ($2 != $4) {
+            printf("%s (%s): %sx%s [%s]\n", $1, $6, $2, $4, $3)
+        } else {
+            printf("%s (%s): %s [%s]\n", $1, $6, $2, $3)
+        }
+    }
+    END {
+        printf("  Total: %d    Suspects: %d\n", n, m);
+    }
+'
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]