I'm working on a web app and currently migrating some stuff from an old app, but I hate that I have to open an image editor to get some info about images I'm migrating. Things like image dimensions.

Is there a command line tool I can use for such tasks in Linux?


14 Answers 14


For some image formats you can just use the file command:

$ file MyPNG.png 
MyPNG.png: PNG image, 681 x 345, 8-bit/color RGB, non-interlaced

Not all image formats report the size (JPEG most notably doesn't):

$ file MyJpeg.jpg 
MyJpeg.jpg: JPEG image data, JFIF standard 1.01

For those you will have to use something more elaborate, like:

$ convert MyJpeg.jpg -print "Size: %wx%h\n" /dev/null
Size: 380x380

The convert command is part of the ImageMagick package.

  • 13
    Could just be me but it seems imagemagick is actually loading image data there as it runs pretty slowly. imo identify should be used instead
    – jozxyqk
    Commented Jun 5, 2014 at 11:23
  • 2
    oh, /dev/null is an argument hehe Commented Dec 9, 2014 at 20:31
  • FWIW this is what I used to get the creation datetime of a photo: identify -format "%[EXIF:DateTimeOriginal]\n" foobar.jpg
    – kralyk
    Commented Aug 13, 2016 at 22:13
  • 4
    Current version of file does support displaying the size of JPEG without additional parameter: $ file foo.jpg returns foo.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 72x72, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=1], baseline, precision 8, 120x120, frames 3
    – Cœur
    Commented Dec 23, 2016 at 9:42

The best way to get this information is by using the identify command:

$ identify image.png

or only size attributes

$ identify -format "%wx%h\n" photo.jpg

** And if you need image details, try the following:

$ identify -verbose image.png

identify is part of ImageMagick, which you can install on Ubuntu like so:

$ sudo apt-get install imagemagick
  • 3
    The specs for the format string can be found in the GraphicsMagick manual.
    – Sjoerd
    Commented Feb 6, 2013 at 19:19
  • 16
    I will add the -verbose flag. I needed to find DPI (that are in the field Resolution)
    – gc5
    Commented Jun 11, 2014 at 15:25
  • 3
    @fbrundu how does DPI relate to a resolution like 72x72
    – Seanny123
    Commented Apr 5, 2016 at 15:37
  • 2
    This worked best for me for SVG files, e.g. file provided: $ file google-forms.svg google-forms.svg: SVG Scalable Vector Graphics image while identify provided: $ identify google-forms.svg google-forms.svg SVG 48x66 48x66+0+0 16-bit sRGB 9543B 0.000u 0:00.006. Exactly what I was looking for, thanks! Commented Jun 2, 2022 at 15:26
  • 1
    Wow identify -verbose {.svg file} is incredibly detailed, if you need more than dimensions and color depth, I'd be surprised if -verbose wouldn't provide the info you need. Commented Jun 2, 2022 at 15:32

exiv2 is "the tool" to get information from picture files:

~$exiv2 myimage.jpg


File name       : myimage.jpg
File size       : 1196944 Bytes
MIME type       : image/jpeg
Image size      : 2592 x 1944
Camera make     : LG Electronics
Camera model    : LG-P970
Image timestamp : 2013:05:19 17:27:06
Image number    : 
Exposure time   : 1/9 s
Aperture        : 
Exposure bias   : 0 EV
Flash           : Yes, compulsory
Flash bias      : 
Focal length    : 3.7 mm
Subject distance: 
ISO speed       : 745
Exposure mode   : 
Metering mode   : Average
Macro mode      : 
Image quality   : 
Exif Resolution : 
White balance   : Auto
Thumbnail       : image/jpeg, 13776 Bytes
Copyright       : 
Exif comment    :
  • do you know when I would get this error from 'exiv2'? Exiv2 exception in print action for file 1059535097558476208.jpg: Failed to read input data
    – Mona Jalal
    Commented Jun 24, 2020 at 20:59
  • Hey Mona Jalal, perhaps it is a faulty image? Have you tried with imagemagick convert/identify yet?
    – shevy
    Commented Feb 27, 2021 at 14:34
  • 1
    Was looking for info on SVG files, unfortunately exiv2 doesn't recognize them: $ exiv2 google-forms-svgrepo-com.svg Exiv2 exception in print action for file google-forms-svgrepo-com.svg: google-forms-svgrepo-com.svg: The file contains data of an unknown image type. identify provides brief and useful info, though. exiv2 looks very useful for other filetypes, though, thank you. Commented Jun 2, 2022 at 15:29

Also, check out ExifTool by Phil Harvey; an example:

$ exiftool test.png 
ExifTool Version Number         : 8.15
File Name                       : test.png
Directory                       : .
File Size                       : 12 MB
File Modification Date/Time     : 2014:02:13 13:04:52+01:00
File Permissions                : rw-r--r--
File Type                       : PNG
MIME Type                       : image/png
Image Width                     : 2490
Image Height                    : 3424
Bit Depth                       : 8
Color Type                      : RGB
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Significant Bits                : 8 8 8
Image Size                      : 2490x3424

Btw, I was looking to get information on dpi/resolution from the command line; and interestingly, sometimes none of these tools report that in an image (like in the above snippet); for more on that, see I want to change DPI with Imagemagick without changing the actual byte-size of the image data - Super User - however, identify -verbose seems to work for the same image as in the previous snippet:

$ identify -verbose test.png 
Image: test.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 2490x3424+0+0
  Resolution: 72x72
  Print size: 34.5833x47.5556
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
      min: 8 (0.0313725)
      max: 255 (1)
      mean: 237.541 (0.931533)
      standard deviation: 37.2797 (0.146195)
      kurtosis: 21.2876
      skewness: -4.56853
      min: 15 (0.0588235)
      max: 255 (1)
      mean: 240.007 (0.941204)
      standard deviation: 37.8264 (0.148339)
      kurtosis: 20.7241
      skewness: -4.51584
      min: 9 (0.0352941)
      max: 255 (1)
      mean: 240.349 (0.942547)
      standard deviation: 38.7118 (0.151811)
      kurtosis: 22.255
      skewness: -4.72275
  Image statistics:
      min: 8 (0.0313725)
      max: 255 (1)
      mean: 179.474 (0.703821)
      standard deviation: 108.711 (0.426316)
      kurtosis: -0.958865
      skewness: -0.995795
  Rendering intent: Undefined
  Interlace: None
  Background color: white
  Border color: rgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 2490x3424+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
    date:create: 2014-02-13T13:11:08+01:00
    date:modify: 2014-02-13T13:04:52+01:00
    signature: bada990d3ba29b311501146d9013d67cf36f667c6d39b1f28a72ce913924397d
    verbose: true
  Tainted: False
  Filesize: 12.52MB
  Number pixels: 8.526M
  Pixels per second: 7.894M
  User time: 1.080u
  Elapsed time: 0:02.080
  Version: ImageMagick 6.6.2-6 2012-08-17 Q16 http://www.imagemagick.org

... although, it can be a bit tricky to read resolution in units of PixelsPerInch using identify -verbose - see ImageMagick • View topic - Cannot set units to pixelsperinch?.

  • Nice: identify -verbose is the only tool I found that reports JPG quality. For example it will say Quality: 90.
    – tanius
    Commented Jul 12, 2019 at 23:38
  • identify -verbose reports something called "pixels per second" measured in ... MB! This scares me off a bit ;).
    – Alexey
    Commented Dec 20, 2020 at 14:52

mediainfo will list detailed metadata for images, audios, and videos. It is usually in the standard repos on Linux, and also available via homebrew on OSX.

From your media folder you can run it as:

mediainfo *


mediainfo .

Both commands will show info on all media files in the current folder and subfolders.

Show info on all JPG images starting from current folder (includes subfolders):

find . -iname "*.jpg" -exec mediainfo {} \;

For audios and videos mediainfo lists the bitrate of audio/video streams, encoding algorithms, container type, FOURCC code, i.e. XVID, X264, etc.

There is a GUI available in standard repos for major distros usually named mediainfo-gui.

identify -verbose image.png

identify is from the ImageMagick package.

It also extract exif informations from jpeg image.


You can try this command if above answers don't work:

rdjpgcom -verbose photo.jpg

It will show info like:

JPEG image is 564w * 779h, 3 color components, 8 bits per sample


Other method not posted above, is using feh (you need to install it):

feh -l image.jpg


1   jpeg    1280    960     1228800 91319       -       image.jpg


feh -l *.jpg

Will output a table (as above) but with all images information (incrementing the NUM column). Useful to use in scripts.


I just discovered that less (with lessfile/lesspipe) can actually display image info by using ImageMagick behind the scene:

sudo apt-get install imagemagick
less wallpaper.jpg


wallpaper.jpg JPEG 1920x1200 1920x1200+0+0 8-bit DirectClass 580KB 0.000u 0:00.000
  • 1
    Is this a joke? I tried this, and it popped up a warning asking me if I really want to read a binary file, and then it just displayed a bunch of binary... (using Ubuntu 14.04) Commented May 10, 2015 at 5:04
  • You need to install ImageMagick for it to work. I mentioned that it uses ImageMagick behind the scene, didn't I?
    – Thanh DK
    Commented May 10, 2015 at 6:21
  • 3
    Quite a dumb way of doing it ... if you have imageMagick installed just use identify command.
    – Mike Q
    Commented Nov 3, 2017 at 21:17
  • Installing ImageMagick has no effect on the output of less.
    – simon
    Commented Nov 14, 2020 at 13:00

The tool you want is file.

It shows a surprising amount of info about all sorts of files.

The syntax is:

$ file my_pic.jpg


You can use :

php -r "print_r(getimagesize('file:///archives/Picture/12 farvardin/20120331_013.jpg'));"

Also you can replace file:// with http://

  • Piggy backing on this you can do the same thing, but using command line args to make it a little easier to use. php -r "print_r(getimagesize(\$argv[1]));" Commented May 5, 2014 at 20:59

If you're dealing with PNGs, there might be attributes that I've found difficult to read with almost any software. For those, you should use pngmeta:

pngmeta file.png

That's particularly useful for thumbnails, since, according to FreeDesktop standard, should be PNG formatted and store path information as a PNG attribute (Thumb::URI).

  • not telling any dpi in ubuntu
    – daparic
    Commented Sep 27, 2019 at 12:15

As provided in the rest of the answers you can use identify command with -verbose flag.

Below is a way to select specific information from the identify output, which is (almost) yaml format.

sudo pip install yq
# OR
pip install --user yq

# note: sed is used to remove what breaks yaml format (first line only).   
identify -verbose image.png | sed 's/^Image:.*/Image:/' \
  | yq -Y '.Image|{"Format","Geometry","Colorspace","Depth","Channel depth","Filesize","Number pixels"}'


Format: JPEG (Joint Photographic Experts Group JFIF format)
Geometry: 1000x714+0+0
Colorspace: sRGB
Depth: 8-bit
Channel depth:
  red: 8-bit
  green: 8-bit
  blue: 8-bit
Filesize: 125KB
Number pixels: 714K

json output (without -Y flag):

  "Format": "JPEG (Joint Photographic Experts Group JFIF format)",
  "Geometry": "1000x714+0+0",
  "Colorspace": "sRGB",
  "Depth": "8-bit",
  "Channel depth": {
    "red": "8-bit",
    "green": "8-bit",
    "blue": "8-bit"
  "Filesize": "125KB",
  "Number pixels": "714K"

Note: tesed with .jpg .png .gif,.tif. Also does not seem to work with .svg (identify output is differrent)


With GraphicsMagick:

# for minimal information
gm identify some-image.png

# for detailed information
gm identify -verbose some-image.png

You must log in to answer this question.

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