强制图像魔术识别以 MB 为单位显示输出大小

Force image magick identify to show output size in MB

如果我运行例如

>identify test_img_2.png 

我明白了

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

是否可以使用某些选项以 MB 为单位输出大小? 通读 man identifyformat 选项,但我不确定如何使用它。

谢谢。

您可以这样做,但对于小文件它会输出零:

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

所以,如果我创建一个大文件:

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

检查尺码 ls:

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

检查 identify MB:

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

或者也包括文件名:

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

如果您想包含其他信息,请查看here可用信息列表。


请注意,如果您使用的是 ImageMagick v7 或更新版本,则变为:

magick identify ...