Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
Inner Sanctum ~/mirror/images $ file wardrobe_square_90.gif
wardrobe_square_90.gif: GIF image data, version 89a, 90 x 90
Inner Sanctum ~/mirror/images $ file wardrobe_square_90.jpg
wardrobe_square_90.jpg: JPEG image data, JFIF standard 1.01
Inner Sanctum ~/mirror/images $ file wardrobe_square_90.png
wardrobe_square_90.png: PNG image data, 90 x 90, 8-bit/color RGB, interlaced

Calling file on some formats gets the images' dimensions, but not JPEG.

I see a way to use ImageMagick to call convert to make a PNG from the JPEG or whatnot, but that has a mild code smell.

Is there a good way to query a JPEG's dimensions?

Thanks,

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

ImageMagick has identify which "describes the format and characteristics of one or more image files."

$ identify bild.jpg 
bild.jpg JPEG 480x640 480x640+0+0 8-bit DirectClass 57.2KiB 0.000u 0:00.000
share|improve this answer
add comment

As with most things UNIX, there are a number of ways to do the same thing.

NetPBM utilities provides a utility pnmfile which, when combined with djpeg, gives file dimensions for JPEG files:

% djpeg default_wallpaper.jpg | pnmfile -
-:      PPM raw, 1920 by 1280  maxval 255

djpeg can be found in many JPEG packages, as can the NetPBM utilities. On Centos/RHEL for example the packages are available from the base repository as: netpbm-progs and libjpeg-turbo

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.