Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform Resize and Fill canvas using Mogrify

The imagemagick site has a demo on this page: http://www.imagemagick.org/Usage/resize/#resize

I want to perform the action in this example:

convert logo: -resize 80x80\> \
          -size 80x80 xc:blue +swap -gravity center  -composite \
          space_resize.jpg

But for a large number of files. I think the right tool is mogrify, but it does not know the +swap or xc:blue flags.

Advice?

like image 280
akoumjian Avatar asked Dec 03 '22 09:12

akoumjian


2 Answers

I was able to accomplish the above by using the following:

mogrify -resize 300x300 *.jpg
mogrify -extent 300x300 -gravity Center -fill white *.jpg

This will make the largest dimension of the images to 300 pixels. It will then fill the canvas on the shorter dimension to 300 pixels and fill in the empty space with white.

like image 141
akoumjian Avatar answered Dec 27 '22 11:12

akoumjian


For me your solution just clips 300x300 portion from my big image.

Next command works correctly, adding white space around image:

mogrify -extent 640x640 -gravity Center -fill white *.jpg[640x640]
like image 22
profuel Avatar answered Dec 27 '22 10:12

profuel