Ubuntu – Resize multiple images with imagemagick from a folder to other (and keep the name) with a command

command lineimage processingimagemagick

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?

Best Answer

This:

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

should work, modify.