Page 1 of 1

Retrieve Height and Width of images

Posted: 2011-02-09T10:49:45-07:00
by Dubben
Hi there,

I have a folder of 70,000+ images, and I need to retrieve the filename, and height/width in pixels of each image, and export them to a text file. I am very new to ImageMagick and programming so any guidance is appreciated.

Cheers.

Re: Retrieve Height and Width of images

Posted: 2011-02-09T11:05:29-07:00
by fmw42
What version of IM do you have and on what platform? If on Unix/Mac, you can use string formats. See http://www.imagemagick.org/script/escape.php

You would have to write a (bash) script to loop over your images, compute the dimensions and write to file. Inside the loop:

convert image -format "%f %w %h" info: >> textfile

The text file will then contain one line for that image with the filename, space, width, space, height. It will append the same information for each image in the loop.

Other unix command alternatives to a bash script for the loop exist also. see http://www.imagemagick.org/Usage/basics/#mogrify_not

For windows users see http://www.imagemagick.org/Usage/windows/

Re: Retrieve Height and Width of images

Posted: 2011-02-09T18:30:06-07:00
by anthony
You can do this in a single pass

Code: Select all

identify -ping-format "%f %w %h\n" *.jpg  > image_info_file.txt
the \n is a newline.

The -ping option asks IM only to read enough of each image to retrieve the arrtibutes (if posible) and not load the full image into memory. Of course if you want something like color counts or other meta-data a 'ping' read may not be enough.

You can even format it in a more complex way such as HTML image tags.
For example this is from
http://www.imagemagick.org/Usage/basics/#identify

Code: Select all

 identify -ping -format '<IMG SRC="%i" ALT="%f" WIDTH=%w HEIGHT=%h>\n' \
            images...

Re: Retrieve Height and Width of images

Posted: 2011-02-15T11:42:44-07:00
by Dubben
Thank you both very much.

I ended up using:

Code: Select all

identify -ping -format "%f %w %h\n" *.jpg  > image_info_file.txt
which worked perfectly for my needs.