Get the dimensions of most images from the command line

Dec 01, '03 10:21:00AM

Contributed by: spacehaven

You can use the file unix command in the Terminal to quickly find the dimensions of (most) images.


karma:~/Sites/somepics me$ file *
yel-pale-grad.gif:  GIF image data, version 89a, 20 x 125
m46.jpg:            JPEG image data, JFIF standard 1.02, resolution (DPI), 200 x 200
troll.png:          PNG image data, 206 x 188, 8-bit colormap, non-interlaced
This is a great help to web developers like me that like to put the image size in img tag. (BTW, I've found some jpeg images return just an aspect ratio of 1x1, but most of the time this works.)

[robg adds: This worked well for me on everything except JPEGs; all my JPEG desktop pictures just show the resolution of the image, not the size.]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031124140353993