2

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?

Zanna
  • 70,465
K_dev
  • 249

3 Answers3

8

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.

George Udosen
  • 36,677
2

Fewer keystrokes:

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

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