Imagemagick – just like magic

I’ve been waiting to send some 150 pictures from my trip to Rome to my father, but have been reluctant since each picture is 2mb+ in size. They were originally in huge resolutions as well, which my father wouldn’t take much joy from given his 1024×768 screen res. Of course I could resize them manually in the Gimp, but since I’ve grown used to batch processing in Photoshop I denied myself the possibility. After a bit of looking at the Script-Fu scripts for the Gimp, I stumbled over this article at novell.com called Batch Resize Images Using Imagemagick. I’ve only tried Imagemagick when working with online gallery scripts, so running it locally just didn’t occur to me.

So, having made a backup copy of the images I simply did:

sigg3[pics]$ mogrify -resize 1024x768! *.JPG

And voilĂ ! All the images had been resized. Gotta love command line image manipulation. Note: this command does not care about image rotation, so it will only work if all your pictures are portrait or landscape format, or you run different commands in different folders. I bet Jamie can give us a few good tips.

4 thoughts on “Imagemagick – just like magic

  1. -auto-orient will pull in the orientation tag from EXIF and rotate smartly. I don’t use it in imagemagick normally. On my camera pics (since I shoot raw), I use -x Orientation from exiftool to do the autorotation for me.

    Another thing you can do is evaluate the height and width using identify

    WIDTH=`identify -ping -format “%[fx:w]” foo.jpg`
    HEIGHT=`identify -ping -format “%[fx:h]” foo.jpg`

    and then use an if/then/else

    if [ $WIDTH -gt $HEIGHT ]
    then
    # convert blah blah
    else
    # convert -rotate 90
    fi

    of course I guess it wouldn’t know if rotate right is correct or not. Maybe the image needed to be rotated 90 degrees, but then now we’re into some really deep wizardry en’ shit (which is way beyond me).

  2. oh, one more comment, if you do resize 640×640 without the !, you’ll get images whose largest dimension will always be 640 without regard to width or height. So my whole last comment is moot.

  3. oh wait… err, no, those are two different problems. Use them both, -auto-orient to rotate , and -resize 640×640 and you’ll have an even conversion; portraits of 480×640, and landscapes of 640×480.

    Maybe I’m having a senior moment or something. Sometimes this shit is confusing.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.