4

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?

akoumjian
  • 1,594
  • 1
  • 15
  • 20

3 Answers3

14

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.

akoumjian
  • 1,594
  • 1
  • 15
  • 20
  • 1
    Also if you have problem with filling image with proper color, try `-background` option instead of `-fill`. – bogumil Sep 24 '15 at 15:05
2

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]
profuel
  • 128
  • 5
1

to extend @akoumjian's resolution I just suggest to use

-transparent white

parameter to get transparent all what was white on the image. It's great for making transparent PNGs

andrej
  • 4,518
  • 2
  • 39
  • 39