File indexing completed on 2024-03-24 05:00:58

0001 #!/bin/sh
0002 
0003 if test "$#" -lt 2; then
0004   echo "Usage: $0 '##|v|h' jpegs"
0005   exit 2
0006 fi
0007 
0008 die() {
0009   echo "$@"; exit 1
0010 }
0011 
0012 notify() {
0013   case "$1" in
0014   /*) url=file:"$1" ;;
0015   *) url=file:"$PWD"/"$1" ;;
0016   esac
0017 
0018   konq=`dcop konqueror-\*`
0019   for k in $konq; do
0020     notify=`dcop $k KDirNotify-\*`
0021     for n in $notify; do
0022       dcop $k $n FilesChanged [ "$url" ]  # $1 must be a url
0023     done
0024   done
0025 }
0026 
0027 
0028 
0029 
0030 action=$1
0031 
0032 case $action in
0033 [1-8]|+[1-8]) o=$action ;;
0034 90|[+-]90) o=+6 ;;  # Use + for all these
0035 270|[+-]270) o=+8 ;;
0036 180|[+-]180) o=+3 ;;
0037 v|-v) o=+4 ;;
0038 h|-h) o=+2 ;;
0039 *) die cannot understand transformation "$action" ;;
0040 esac
0041 
0042 shift
0043 
0044 for file in "$@"; do
0045 
0046 if orient.py $o "$file" | grep 'orientation changed' >/dev/null 2>&1; then
0047   notify "$file"
0048   continue
0049 fi
0050 
0051 ### try jpegtran instead
0052 if which jpegtran-mmx >/dev/null 2>&1; then
0053   JPEGTRAN=jpegtran-mmx
0054 else
0055   if which jpegtran >/dev/null 2>&1; then
0056     JPEGTRAN=jpegtran
0057   else
0058     die could not change orientation
0059   fi
0060 fi
0061 
0062 case $action in
0063 v|-v) c='-flip vertical' ;;
0064 h|-h) c='-flip horizontal' ;;
0065 *90) c='-rotate 90' ;;
0066 *180) c='-rotate 180' ;;
0067 *270) c='-rotate 270' ;;
0068 +5) c='-transpose' ;;
0069 +7) c='-transverse' ;;
0070 *) die cannot understand transformation "$action" using jpegtran ;;
0071 esac # others could be emulated, but ...
0072 
0073 tmp="$file.a.$$"
0074 
0075 cleandie() {
0076   mv -i "$tmp" $"2" </dev/null 2>/dev/null; die "$@"
0077 }
0078 
0079 mv -i "$file" "$tmp" </dev/null 2>/dev/null || die unable to move temp files
0080 $JPEGTRAN -copy all -outfile "$file" $c "$tmp" || cleandie error using jpegtran
0081 rm "$tmp"
0082 notify "$file"
0083 
0084 done
0085