38

I have an image called ZEAKR.jpg. How can I know its size and format from the command line?

Elephants

2 Answers 2

60

Use the command identify, which is part of ImageMagick.

Examples:

$ identify ZEAKR.jpg 
ZEAKR.jpg JPEG 400x600 400x600+0+0 8-bit DirectClass 49.9KB 0.000u 0:00.000

or

$ identify -verbose ZEAKR.jpg 
Image: ZEAKR.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 400x600+0+0
  Resolution: 72x72
  Print size: 5.55556x8.33333
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 37.8679 (0.148501)
      standard deviation: 83.5317 (0.327575)
      kurtosis: 1.46576
      skewness: 1.83875
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 60.6554 (0.237864)
      standard deviation: 54.9167 (0.21536)
      kurtosis: 1.74308
      skewness: 1.84745
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 67.6817 (0.265418)
      standard deviation: 28.1072 (0.110224)
      kurtosis: 0.599932
      skewness: -0.97633
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 55.4017 (0.217261)
      standard deviation: 59.9539 (0.235113)
      kurtosis: 2.34592
      skewness: 1.64301
  Rendering intent: Undefined
  Interlace: None
  Background color: white
  Border color: rgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 400x600+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 96
  Orientation: Undefined
  Properties:
    date:create: 2012-06-23T11:22:15-05:00
    date:modify: 2012-06-23T11:22:15-05:00
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: 2beab0779fc657fb62e8609b600d90d1e502f614794e497299ffaa28d145408e
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 49.9KBB
  Number pixels: 240KB
  Pixels per second: 24MB
  User time: 0.000u
  Elapsed time: 0:01.009
  Version: ImageMagick 6.6.9-7 2012-04-30 Q16 http://www.imagemagick.org
3
  • Very good. I have known about ImageMagick for a while (mostly the incredibly awesome import command), but it still continues to surprise me.
    – fouric
    Jun 23, 2012 at 18:02
  • I expected imagemagick to be a very large library and therefore for the built-in file answer from @randmin to be preferred, but imagemagick version 6.9.11.27 available for Fedora 34 is only 645 kB! Good answer, @Agmenor
    – call-in-co
    Sep 8, 2021 at 22:05
  • We have found that file doesn't reliably return the image dimensions. Imagemagick's identify is far more reliable but obviously requires Imagemagick to be installed. Jan 30 at 10:41
7

For everyone else looking for a solution that is included in (most) distributions by default, here it is:

Command: $ file <imagename>

Output: <imagename>: PNG image data, 100 x 10, 8-bit/color RGB, non-interlaced where 100 x 10 represents width x height respectively.

The file command shows dimensions of many image types. I add this solution because I generally try to avoid installing additional software, and ImageMagick (although awesome!) is using a sledgehammer to crack a nut here.

4
  • You need to be in the directory of the image. Passing full path will give you filenotfound or other error.
    – Ahmad Anis
    Aug 9, 2021 at 7:09
  • @AhmadAnis that is not true at least on Fedora 34: [c@deskmini ~]$ file ~/Pictures/Sero-LSD-Psilo-RED.png /home/c/Pictures/Sero-LSD-Psilo-RED.png: PNG image data, 900 x 316, 4-bit colormap, non-interlaced
    – call-in-co
    Sep 8, 2021 at 21:58
  • @randmin good call: this is in the manpage for file: There has been a file command in every UNIX since at least Research Version 4 (man page dated November, 1973)
    – call-in-co
    Sep 8, 2021 at 22:02
  • We have found that file doesn't reliably return the image dimensions. Imagemagick's identify is far more reliable but obviously requires Imagemagick to be installed. Jan 30 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .