Add border around selection

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
kboehme1
Posts: 5
Joined: 2016-12-12T22:43:19-07:00
Authentication code: 1151

Add border around selection

Post by kboehme1 »

OS: MacOS
Version: ImageMagick 7.0.5-0 Q16 x86_64 2017-02-21 http://www.imagemagick.org

I have an image that is a black outline on transparent background.
https://www.dropbox.com/s/6t9r4m408ljre ... e.png?dl=0

I would like to select all black color and add a 2 pixel red border around it.

https://www.dropbox.com/s/65udncxwuqmsp ... e.png?dl=0
Last edited by kboehme1 on 2017-02-28T16:33:44-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add border around selection

Post by fmw42 »

Perhaps it would be best to upload your image to some free hosting service such as dropbox.com and put the URL here so we can fully understand your problem.
kboehme1
Posts: 5
Joined: 2016-12-12T22:43:19-07:00
Authentication code: 1151

Re: Add border around selection

Post by kboehme1 »

fmw42 wrote: 2017-02-27T01:17:58-07:00 Perhaps it would be best to upload your image to some free hosting service such as dropbox.com and put the URL here so we can fully understand your problem.
Updated the question to include examples.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add border around selection

Post by fmw42 »

try this:

Code: Select all

convert shape.png \
\( -clone -0 -background red -flatten \) \
\( -clone -0 -alpha extract -morphology dilate diamond:2 \) \
-delete 0 -alpha off -compose copy_opacity -composite \
-background black -alpha background result.png
kboehme1
Posts: 5
Joined: 2016-12-12T22:43:19-07:00
Authentication code: 1151

Re: Add border around selection

Post by kboehme1 »

That works great. Thanks!
Post Reply