To get Width and Height of Images

Hi,

Could anyone suggest me how to get the width and height of images.

The images can be of any type (tif, eps, jpeg).

Thanks,
Gopal

Assuming the image has been indexed by Spotlight this would probably be the easiest way as it does not involve launching a program to get the data for you.

set theFile to choose file
set {PixelHeight, PixelWidth} to paragraphs of (do shell script "/usr/bin/mdls -name kMDItemPixelHeight -name kMDItemPixelWidth " & (quoted form of POSIX path of theFile) & "| /usr/bin/awk -F\" = \" '{print $2}'")

And here’s the method Apple provides using Image Events

set theFile to choose file
try
	tell application "Image Events"
		launch
		set this_image to open theFile
		copy the dimensions of this_image to {PixelWidth, PixelHeight}
		close this_image
	end tell
on error error_message
	display dialog error_message
end try

And this other command line versions uses sips so you don’t have to worry about wether the file has been indexed or not.

set theFile to choose file
set {PixelHeight, PixelWidth} to paragraphs 2 thru 3 of (do shell script "/usr/bin/sips -g pixelHeight -g pixelWidth " & (quoted form of POSIX path of theFile) & "| /usr/bin/awk -F\": \" '{print $2}'")