Andre
Andre

Reputation: 673

imagemagick: center and resize multiple images an keep original filename

Good morning,

I'd like to center and resize multiple images in a folder with different aspect ratios and keep the filename. The following is nearly what I like to have (it works perfect for the particular picture), but there I have to name every specific pic.

convert -size 100x100 xc:black -gravity center originalpic.jpg -thumbnail 300x300 -composite newpic.jpg

I tried to work with * to keep the original file name and to process every file in the folder but without success. Does anybody know how to do that?

Thank you!

Upvotes: 3

Views: 1794

Answers (2)

enrico.bacis
enrico.bacis

Reputation: 31494

Use the mogrify command to work with multiple files.

mogrify -size 100x100 xc:black -gravity center -thumbnail 300x300 -composite *.jpg

Another way would be to iterate over the images in bash and use the same name as output to overwrite:

for f in *.jpg
do convert -size 100x100 xc:black -gravity center $f -thumbnail 300x300 -composite $f
done

Upvotes: 6

Andre
Andre

Reputation: 673

I think I got it for me in general:

First size down to the height you want, e.g. to 364px:

mogrify -resize x364 *.jpg

And then, e.g. you want to get a dimension of 546x364px, this:

mogrify -extent 546x364 -gravity center *.jpg

But at image with original size of 512x768 background is getting filled with white color, so I tried

mogrify -extent 546x364 -gravity center -background black *.jpg

and

mogrify -extent 546x364 -gravity center -fill black *.jpg

but background is still white :-(

Upvotes: 0

Related Questions