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 size | exiftool speed | ImageMagick speed | |
image1.png | 512K | 0.459s | 0.383s |
image2.png | 1.6M | 0.363s | 0.332s |
image3.png | 3.5M | 0.331s | 0.360s |
image4.jpg | 10M | 0.354s | 0.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