Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Get the dimensions of most images from the command line UNIX
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.]
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[20,320 views]  

Get the dimensions of most images from the command line | 4 comments | Create New Account
Click here to return to the 'Get the dimensions of most images from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Get the dimensions of most images from the command line
Authored by: fxt on Dec 01, '03 12:29:50PM

sips is more powerful for image files.

http://www.macosxhints.com/article.php?story=20031115005418881

to get the image size, rather than the resolution use

% sips -g pixelHeight -g pixelWidth image(s)

fxt



[ Reply to This | # ]
Get the dimensions of most images from the command line
Authored by: spiffy on Dec 01, '03 12:53:16PM
To get the dimensions of JPEG images (and pretty much all other image types) you can use ImageMagick's identify command. ImageMagick is available via fink.

[ Reply to This | # ]
Get the dimensions of most images from the command line
Authored by: aubreyapple on Dec 08, '03 07:16:29PM

With X.2.8, and trying to use identify, as suggested:

%identify file.jpg
identify: No decode delegate for this image format (file.jpg).
% which identify
/usr/local/bin/identify
% identify -version
Version: ImageMagick 5.5.7 10/20/03 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 2003 ImageMagick Studio LLC
% file file.jpg
file.jpg: JPEG image data, JFIF standard

Any ideas? This is true for all the jpeg images I have tried.



[ Reply to This | # ]
Get the dimensions of most images from the command line
Authored by: bluehz on Dec 07, '03 09:27:08AM

Create an alias in your shell profile (or your fav method of alias) like this:

# get image dimensions
alias imgdim 'sips -g pixelHeight -g pixelWidth $1'

and then just use:
imgdim filename

Matter of fact it even works with multiple files. For example:
imgdim *.pdf



[ Reply to This | # ]