Using ImageMagick to add white space to images in bulk
I have a bunch of images that are rectangular and I need them to be square, that is, 1000x1000, so I decided to use ImageMagick to pad the sides of the image with as many spaces as needed to create a square of the image.
I found the code from the following link helpful (see next paragraph). But this requires me to process each image separately to give the filename and then the size of the thumbnails. How can I use this same process to process an entire folder?
Here's the code and link to it:
http://imagemagick.org/Usage/thumbnails/#pad
convert -define jpeg:size=200x200 hatching_orig.jpg -thumbnail '100x100>' \
-background white -gravity center -extent 100x100 pad_extent.gif
source to share
It is not entirely clear from your question what you actually have (that is, how big are your images, what format are they in?) And what you actually want (you only provide an example that does not do what you want. But I'll take your question on the front title board and hope you can find something that's missing there.
If you want to do ImageMagick in bulk, you either need to use a loop in bash
, for example:
#!/bin/bash
for f in *.jpg; do
convert "%f" ...
done
or use the IM command mogrify
. It's a pretty powerful command, so back up your images before you even try to use it.
Let's JPEG
say you want to place all images in the current directory on a 1000x1000px white background. You would do this:
mogrify -background white -gravity center -extent 1000x1000 *.jpg
Updated answer
It should be possible to do the resizing and white padding in one ImageMagick command without the need for SIPS, for example if you now want 1200x1200 square images to be padded with white:
mogrify -background white -gravity center -resize 1200x1200\> -extent 1200x1200 *.jpg
source to share