Let's say that the images are in the directory /Desktop/projs/proj1/img/ and I want the output files to go to /Desktop/projs/proj1/imgResized/.

I tried this command:

convert /Desktop/projs/proj1/img/*.png -resize 130x130\! /Desktop/projs/proj1/imgResized/converted.png

This works, but the output images are renamed to converted-0.png, converted-1.png, etc.

I tested other commands to see if the images keep their names:

for PHOTO in /Desktop/projs/proj1/img/*.png; do BASE=`basename $PHOTO` convert /Desktop/projs/proj1/img/*.png -resize 130x130 /Desktop/projs/proj1/imgResized/$BASE.png; done;

But it’s not working.

How can I do this? And if possible, how can I do the same but for compressing all the images from folder A to B?

  • Your second code is wrong it should be convert "$PHOTO" . The for variable should be used. Aug 26, 2018 at 14:26
  • And I see that you have /Desktop that directory does not exist except you created else it should have been /home/$USER/Desktop Aug 26, 2018 at 14:31

3 Answers 3



for i in /home/$USER/Desktop/projs/proj1/img/*.png; do 
    convert "$i" -resize 130X130 "/home/$USER/Desktop/projs/proj1/imgResized/${i##*/}"

should work, modify.

  • $i includes /Desktop/projs/proj1/img/
    – Vijay
    Aug 25, 2018 at 16:57
  • "$i" are the individual files in that folder img! Aug 25, 2018 at 17:04
  • Try this >> for i in ~/Desktop/projs/proj1/img/*.png; do echo $i; done
    – Vijay
    Aug 25, 2018 at 17:21
  • Your point @Vijay? Aug 25, 2018 at 17:28
  • 1
    Thanx for the edit works now.
    – Vijay
    Aug 27, 2018 at 12:13

Fewer keystrokes:

 for i in ~/Desktop/projs/proj1/img/*.png; do convert "$i" -resize 130X130 "${i/img/imgResized}"; done

Welcome to 2023! Surprised mogrify was not mentioned in connection with imagemagick.

Assuming the imgResized directory already exists, the below should work fine from the directory containing the original images, and keep the original names. No loops necessary.

mogrify -resize 130x130 -quality 100 -path ~/Desktop/projs/proj1/imgResized/ *.png

You must log in to answer this question.

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