#!/bin/sh # # /usr/local/bin/exif-res.sh # # Copyright 2012 - Jean-Sebastien Morisset - http://surniaulula.com/ # # This script is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # This script is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details at http://www.gnu.org/licenses/. # Read command line opts while : do for arg in "$@" do case $arg in -w|--width) opt="w"; shift 1;; -h|--height) opt="h"; shift 1;; -s|--size) opt="s"; shift 1;; -v|--vars) opt="v"; shift 1;; --help) echo "" echo "Syntax: $0 [--[width|height|size|vars]] {filepaths...}" echo "" echo "--width Print the width of the image" echo "--height Print the height of the image" echo "--size Print the width or height of the image - whichever is greater" echo "--vars Print the width and height as variables that can be eval'ed" echo "" echo "Without any command line options, the script prints the width and height (as WxH)" echo "" echo "Example: eval \`$0 --vars image.jpg\`; echo \"\$W by \$H\";" echo "" exit 0 ;; -*) echo "error: $arg parameter unknown." exit 1 ;; *) args[$(( i++ ))]="$1"; shift 1;; esac continue 2 done break done # reset $1, $2, etc. with left-over paramters set -- "${args[@]}" for filepath in "$@" do if [ -f "$filepath" -a -r "$filepath" ] then eval `exiftool "$filepath" | sed -n 's/^Image Size *: \([0-9][0-9]*\)x\([0-9][0-9]*\)$/W=\1; H=\2/p'` if [ "$W" -a "$H" ] then case "$opt" in w) echo $W ;; h) echo $H ;; s) [ "$W" -gt "$H" ] && echo "$W" || echo "$H" ;; v) echo "W=${W};H=${H}" ;; *) echo "${W}x${H}" ;; esac fi fi done