Resize and fill the canvas with Mogrify

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

I want to perform an 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 correct tool is mogrify, but it does not know the + swap or xc: blue flags.

Tip

+4
source share
3 answers

I managed to accomplish the above using the following:

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

This will make the largest image size up to 300 pixels. Then it will fill the canvas at a shorter distance of up to 300 pixels and fill the empty space with white.

+12
source

For me, your solution just clamps the 300x300 portion of my large image.

The following command works correctly by adding a space around the image:

 mogrify -extent 640x640 -gravity Center -fill white *.jpg[640x640] 
+2
source

to extend @akoumjian resolution, I just suggest using

 -transparent white 

to get the transparency of everything that was white in the image. This is great for creating transparent PNGs.

+1
source

Source: https://habr.com/ru/post/1343926/


All Articles