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.
Retrieve Height and Width of images
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Retrieve Height and Width of images
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/
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/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Retrieve Height and Width of images
You can do this in a single pass
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 "%f %w %h\n" *.jpg > image_info_file.txt
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...
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Retrieve Height and Width of images
Thank you both very much.
I ended up using:
which worked perfectly for my needs.
I ended up using:
Code: Select all
identify -ping -format "%f %w %h\n" *.jpg > image_info_file.txt