I use a tool to generate hundreds of photos and in the end I want to add some padding to the photo, but not manually because this will take a lot of time for more than 10000 photos.

So for instance if I generate a photo 800x800 and in the end I want to have a photo 850x850. The extra 50px should be transparent.

Is there any tools that can do this from code?

  • \$\begingroup\$ you can record and playback a photoshop action and run it in bulk, if the command line scares you away. \$\endgroup\$
    – dandavis
    Oct 27, 2021 at 20:38

2 Answers 2


To have transparency you should store the images as PNG format (for example). From command line you can use ImageMagic with command:

convert source.jpg -resize 800x800 -gravity center -background transparent -extent 850x850  target.png

If you are fine with graphical tool you can use XnView MP, open in browser mode, select images, Ctrl+U, on Actions tab add Image->Canvas Resize, select Relative and enter 25 for Wight and Height. For background select colour which do not exist on your images. enter image description here Then add Action Image->Transparent color and select the colour you add above. enter image description here In Output tab select PNG format and press Convert. P.S. Both tools are available for Windows, Linux and MacOS

If you want to use multiply cores in XnView in Output tab select "Use multiply CPU Cores" and drag the slice on desired number of cores. enter image description here


Romeo Ninov's answer is great, but I think there are simpler invocations of the ImageMagick convert program. Both of the following do the same thing:

convert 'input-file' -matte -bordercolor none -border 25 'output-file'
convert 'input-file' -mattecolor none -frame 25 'outout-file'

The options are:

  • -matte — ensures that the border color none is an RGBA (RGB plus alpha) color (rgb(0, 0, 0, 0.0), and not just rgb(0, 0, 0), by adding an alpha channel to the entire image (if it doesn't already have one).
  • -bordercolor none — the border color to apply (as discussed above)
  • -border border-width — the size of the border, in pixels, to be applied. In this example, because you wanted an output image 50 pixels larger than the original, the border width is half that amount.
  • 'input-file' and 'output-file' should be the input & output filenames, respectively. Fairly obvious. Note that the image format of 'output-file' must be able to support alpha transparency. For instance, if the output format is JPEG (by using a .jpg extension), the border won't be transparent. PNG supports transparency. If the formats of 'input-file' and 'output-file' are different, then ImageMagick will automatically convert from the former format to the latter.

In the 2nd example, -mattcolor none (when used with the -frame option) does the same thing as separately specifying -matte and -bordercolor (when they are used with the -border option).

See also:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.