I am trying to loop through a directory of images and trying to get the resolution of multiple images at the same time and display them. How can I do this?

my images are in .jpeg and .png format. The names have '_' character like Transverse_H4096_W4096.jpeg and thumb.png

  • Are all the images the same format? What are the names like? Can the names contain spaces? Newlines? Other strange characters? What tool do you use to the resolution? Please edit your question and clarify.
    – terdon
    Jul 18, 2017 at 12:43
  • my images are in .jpeg and .png format. The names have '_' character like Transverse_H4096_W4096.jpeg . Jul 18, 2017 at 13:24
  • 1
    Please edit your question and add this information. Comments are hard to read, easy to miss and can be deleted without warning.
    – terdon
    Jul 18, 2017 at 13:30

2 Answers 2


Using ImageMagick's identify to get the resolution of all JPG files in the current directory:

for image in *.jpg *.jpeg *.png
   echo "$image :"
   identify -format "%[fx:w]x%[fx:h]\n" "$image"
  • Thank you. It works. But my folder is a combination of both jpeg as well as png files. How can I get information of all kinds of image extensions at the same time. Jul 18, 2017 at 13:40
  • I've edited the answer.
    – dr_
    Jul 18, 2017 at 13:48
  • 1
    @MaradaniLavanya see, that's why you need to explain all this in your question.
    – terdon
    Jul 18, 2017 at 14:21
  • I am sorry for that. And thank you . It works Jul 18, 2017 at 17:20
  • If this solution worked for you, please consider accepting this answer so other readers can find it more easily. Thanks.
    – dr_
    Jul 19, 2017 at 8:33

You could use exiftool to get images metadata.

To install the tool on Debian/Ubuntu:

sudo apt-get install libimage-exiftool-perl

On Arch Linux:

sudo pacman -Sy perl-image-exiftool

Where -S is to syncronize packages (packages are installed directly from the remote repositories, including all dependencies required) and -y is to download a fresh copy of the master package database from the server(s) defined in pacman.conf(5) (from man pacman) .

Then to extract the needed data:

for image in ./images/*
   exiftool "-*FileName*" "-*ImageSize*" "$image"

The output will be:

File Name                       : linux.jpg
Image Size                      : 1920x1080
File Name                       : background.jpg
Image Size                      : 1020x980

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .