2008-04-28

Orient JPEGs so if in portrait orientation, rotate 90 degrees to make a landscape image

Useful to get maximum resolution available on e.g. regular or widescreen monitors to view images.

$ cat wide-orientation
#!/bin/sh

for f in "$@" ; do

  eval `identify "$f" | cut -f3 -d' ' | sed  's/x/; export H=/ ; s/^/export W=/' `
  if [ "$H" -gt 0  -a  "$W" -gt 0  -a  $H -gt $W  ] ; then
    echo Changing $f from ${W}x${H} to ${H}x${W}...
    #convert -verbose -rotate "90<" $f $f
    jpegtran -rotate 90 -trim "$f" > "$f.1"
    mv -f "$f.1"  "$f"
  else
    echo Not altering "$f"...
  fi

   # this alone will do it, but it's SLOW
   # convert -verbose -rotate "90<" $f $f

done


# vim:ft=sh

No comments: