[Nottingham] Bash script problem

Camilo Mesias camilo at mesias.co.uk
Sun Mar 1 11:28:50 UTC 2009


I think there's a problem with the let line (I'm not that familiar
with the use of let in bash though, haven't seen it often)

The exiftags grep line outputs a string to stdout like this
Image Width: 3776

So your WIDTH and HEIGHT are probably both empty.

Since your script is doing the right thing anyway without the size
calculation working properly, you could just use a convert:

        convert -thumbnail 200x150 "$file" thumbnails/"$thumbfile"

Or I think I've used -size 200x200 (ie giving the maximum width or
height regardless of orientation) and it seems to do the right thing.

It's a pain if you have lots of different size images to work on -
4:3, widescreen, 3:2 etc. I'm not sure there is a good answer. Also
some images have orientation built in: eg. "Image Orientation: Top,

If you really wanted to read the width and size from an image I would
use something like

WIDTH=$(exiftags file.jpg |grep "Image Width"|awk '{ print $NF }')

Or I would use Perl and an Image::Size package or similar which would
work with images that didn't have exif data too.


More information about the Nottingham mailing list