0
votes

I have a number of PNG image files that I'd like to increase in size. I do not want to rescale the image. I just want to extend the white background further down and to the right. In GIMP terms what I want is to increase the Canvas Size, and cover the increased area with white pixels, in a batch context. The input images may be different sizes, but the output images should all be a fixed size (e.g.: 1280 x 720 pixels).

I've tried this with various online tools, with GIMP, and with a very old version of Photoshop. Most of the tools I've tried to date do one of the following which I don't want:

  • Rescale the existing image to cover the new canvas size, or
  • Center the starting image and extend the canvas in all directions, or
  • Fail to perform this in a batch mode.

I just want to extend existing PNG images with additional white pixels down and to the right. What's the easiest way to do this to a large number of files?

2

2 Answers

1
votes

imagemagick is a common tool for this. the -crop operation combined with -gravity can probably do what you want.

magick input.jpg -crop 1000x1000+0+0\! -background white -flatten output.png

source for the magick spell: https://legacy.imagemagick.org/Usage/crop/

input output

1
votes

In ImageMagick, you process a whole folder of images using mogrify. You can extend them using -extent. With mogrify, it is wise to first create a new empty directory to hold the results. So

cd image_directory
mogrify -format png -path path/to/new_directory -background white -gravity northwest -extent WxH *.png

Where WxH, is your desired final width and height after padding with the white. This assumes that all images will be padded to the same width and height

Expand By Size

cd test1
mogrify -format png -path ../test2 -background white -gravity northwest -extent 500x500 *.jpg

Expand By Percent

cd test1
mogrify -format png -path ../test2 -background white -gravity northwest -extent 150x150% *.jpg

For ImageMagick 7, add magick before mogrify. So "magick mogrify ..."