Avi C Avi C - 6 months ago 42
Bash Question

ImageMagick command to convert and save with same name

I am using ImageMagick convert command for making thumbnails & save the converted images in another directory, one by one, in PHP.

But, cant figure out how to keep the the image name in the converted image.

> convert 1.JPG -resize 120X120 thumb/*.JPG

need to keep the output file names same as the input. Please help.


A simple solution would be copy, followed by mogrify - another imagemagick tool - this will keep the same names, it takes all the same args as convert.

cp *.jpg thumb/
cd thumb
mogrify -resize 120X120 *.JPG

Alternatively you could do a bit of shell scripting, using find -exec or xargs

# using -exec
find . -iname "*.JPG" -maxdepth 1 -exec convert -resize 120x120 {} thumbs/{} \;

# using xargs
find . -iname "*.JPG" -maxdepth 1 | xargs -i{} convert -resize 120x120 {} thumbs/{}