How to Quickly and Easily Check Image Size using Linux Terminal

How to Quickly and Easily Check Image Size using Linux Terminal

If you want to see how many megapixels an image has under Linux, especially in a shell script, it is usually not easy. However, I have found two solutions that make it easy to check this, just by issuing a command. I also compared them at the bottom of this article.

The first solution is exiftool

Installation: sudo apt install exiftool

Using it is simple, just substitute the path to the image in the command below:

exiftool -s -ImageSize /path/image1.png | awk '{print $3}' | awk -Fx '{print ($1 * $2) / 1000000}'

 

The second solution is ImageMagick

Installation: sudo apt install imagemagick

Using it is simple, just substitute the path to the image in the command below:

identify -format "%wx%h" /path/image1.png | awk -Fx '{print ($1 * $2) / 1000000}'

 

Speed comparsion

 Picture sizeexiftool speedImageMagick speed
image1.png512K0.459s0.383s
image2.png1.6M0.363s0.332s
image3.png3.5M0.331s0.360s
image4.jpg10M0.354s0.400s

Conclusion

Both solutions are great for displaying how many megapixels the image is. However, if that's the only goal, I would personally choose exiftool because of the less storage space it takes up.

Comments