Command-Line Tool – How to Get Information About an Image from the Linux Command-Line

command linecommand-line-toolimage processing

Am working on a web-app, and currently am 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 am migrating. Things like image dimensions.

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

Best Answer

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.