Home > Net >  Bulk resize folder of images to two different sizes and rename files imagemagick (Mac OS)
Bulk resize folder of images to two different sizes and rename files imagemagick (Mac OS)

Time:05-24

I'm looking to loop through a number of images in a folder, resize and crop them to two different sizes, then rename them. I can get one set to work with this code:

for f in *.png; do convert "$f" -resize 1500x \! -gravity Center \! -extent 1500x500 \! -set filename:f "%[t]-twitter" "%[filename:f].png"
done

which gives me a nice sized image, cropped from the center. If I then run this again to crop to 1100px wide I end up creating two versions as I'm creating from the originals and my resized for twitter images. I can't find a way to combine multiple resizes and re-names and run in bulk from one folder, whilst outputting into the same folder. Does anyone have any suggestions at all please?

CodePudding user response:

In Imagemagick, you can do it as follow, I believe (untested). the -extent will crop if needed otherwise it will pad (so you may want to set the -background color before -extent, even if it is not used)

for f in *.png; do 
convert "$f" -set filename:f "%[t]-twitter" \
\( -clone 0 -resize 1500x -gravity Center -extent 1500x500   write "%[filename:f]_1500.png" \) \
\( -clone 0 -resize 3000x -gravity Center -extent 3000x100   write "%[filename:f]_3000.png" \) \
null:
done

The above will resize the input to two different sizes. You can specify the sizes as you want.

If you want to resize the first resize to make the second, then change -clone 0 to -clone 1.

  • Related