skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    The ImageMagick command that did what I needed used "convert" with the -geometry and -composite arguments. In a Windows batch file context:

    for %%a in (img*.png) do (
       magick convert -size 1280x720 xc:white "%%a" -geometry 512x384+40+40 -composite "work-%%~na.pdf"
    )
    

  2. 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

    Login or Signup to reply.
  3. 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 …"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search