Page 1 of 1

Adding transparent border to png images

Posted: 2018-01-13T23:30:06-07:00
by bigbad
Noob question. New to magick. I need to batch add transparent padding to thousands of .png images of varying dimensions. I need to increase the size of the canvas so that there is 20px of transparent space added to the height and width of every image, similar to how you would add 20px to the canvas size in photoshop to add extra space around the image. Can anyone help me with this?

Re: Adding transparent border to png images

Posted: 2018-01-14T00:50:59-07:00
by fmw42
Please always provide your IM version and platform, since syntax may differ.

In IM 6, you can do that for all images in a given directory using mogrify. Best to create a new directory to hold the output in case of mistakes before using mogrify. It will not create directories.

Code: Select all

cd to current_directory
mogrify -path path2/new_directory -bordercolor transparent -border 20 -format png *.png
in IM 7, the syntax is slightly different

Code: Select all

cd to current_directory
magick mogrify -path path2/new_directory -bordercolor transparent -border 20 -format png *.png
For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

In particular, see
https://www.imagemagick.org/Usage/basics/#mogrify
https://www.imagemagick.org/Usage/crop/#border

Re: Adding transparent border to png images

Posted: 2018-01-14T01:34:55-07:00
by bigbad
Thank you. This helped me a lot.