# Getting an image file's dimensions quickly



## Mikuro (Nov 6, 2006)

I'm writing a program that needs to get the width and height of large groups of images. I want to get the dimensions without actually loading the image (since that takes too long). The Finder has been able to quickly do this with a wide variety of image formats for years, but I can't figure out how to do it myself.

Any ideas?

I would love to be able to do this in AppleScript or REALbasic, but I'm open to other options like Cocoa.


----------



## eric2006 (Nov 6, 2006)

This probably isn't helpful to your goal, but you can get the metadata in Automator, which includes dimensions:
http://automatoractions.com/files/getimagefilemetadata1.0.html


----------



## Natobasso (Nov 7, 2006)

Here's a way to do it using Safari:
http://www.macosxhints.com/article.php?story=20030829230125498

Could be worked into an automator task...


----------



## Captain Code (Nov 7, 2006)

I found this for jpegs
http://www.andrew.cmu.edu/user/twm/stuff/jpegsize.html

It should be in the headers of each image but how you read those images are always going to be different based on the headers of the file.


----------



## Mikuro (Nov 7, 2006)

Thanks guys.

iMagine Photo (the application that Automator action that Eric posted uses) is a nice find. It lets AppleScript/Automator users do a bunch of things with images, and a quick test shows pretty good performance getting image dimensions. It's about 4x faster than my code in REALbasic, and about 8x faster than a similar AppleScript based on System Events. Relying on a third-party app is not ideal, but if I can't come up with anything better, I could go with it.


With a little more googling, I found something called ExifTool that looks promising as well. I haven't had time to really look into it, but it says it supports a ton of image files and it sounds like it can return the metadata without loading the image data (i.e., _quickly_).


----------

