#!/bin/bash umask 002 copy_all_size="300" # keep exif for images larger than this size # read command line opts while : do for arg in "$@" do case $arg in -d|--days) mins=$(( $2 * 1440 )) shift 2 ;; -h|--hours) mins=$(( $2 * 60 )) shift 2 ;; -m|--mins) mins=$2 shift 2 ;; -*) 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[@]}" [ -n "$mins" ] && opts="$opts -mmin -$mins" for dir in "$@" do [ -d "$dir" -o -f "$dir" ] && \ find "$dir" $opts -regextype posix-egrep -regex '^.*\.(jpg|png|gif)$' \ -print 2>/dev/null | while read img do # get the image width and height as variables eval "`/usr/local/bin/exif-resolution.sh -v \"$img\"`" [ "$W" -gt "$H" ] && size="$W" || size="$H" # keep exif for images larger than $copy_all_size [ "$size" -gt "$copy_all_size" ] && copy="all" || copy="none" # exceptions case "$img" in */wordpress/wp-content/themes/*) copy="none" ;; */wordpress/wp-content/plugins/*) copy="none" ;; esac echo -e "$img (${W}x${H}, copy $copy) \c" /usr/local/bin/wesley.pl --copy="$copy" "$img" 2>/dev/null | grep 'Total bytes saved:' | xargs done done