Adding transparent border to png images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bigbad
Posts: 2
Joined: 2018-01-13T23:22:21-07:00
Authentication code: 1152

Adding transparent border to png images

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding transparent border to png images

Post 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
bigbad
Posts: 2
Joined: 2018-01-13T23:22:21-07:00
Authentication code: 1152

Re: Adding transparent border to png images

Post by bigbad »

Thank you. This helped me a lot.
Post Reply