user8469759
user8469759

Reputation: 2732

Force image magick identify to show output size in MB

If I run for example

>identify test_img_2.png 

I get

>test_img_2.png PNG 256x256 256x256+0+0 16-bit sRGB 371KB 0.000u 0:00.000

Is it possible with some options to output the size in MB? Reading through man identify there's the format option, but I'm not sure how to use it.

Thank you.

Upvotes: 1

Views: 848

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207758

You could do this but it will output zero for small files:

identify -format "%[fx:int(extent/(1024*1024))]"  image.jpg

So, if I create a big file:

convert -size 10000x10000 xc:red +noise random a.jpg

Check the size with ls:

ls -l a.jpg
-rw-r--r--@ 1 mark  staff  174312876  4 Feb 17:51 a.jpg

Check with identify in MB:

identify -format "%[fx:int(extent/(1024*1024))]"  a.jpg
166

Or include the filename too:

identify -format "%f: %[fx:int(extent/(1024*1024))]"  a.jpg
a.jpg: 166

If you want to include other info, look here at the list of available information.


Note that if you are using ImageMagick v7 or newer, that becomes:

magick identify ...

Upvotes: 2

Related Questions