Need help in creating a tranparency border

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
sevasjack

Re: Need help in creating a tranparency border

Post by sevasjack »

You can make border and fill it with semitransparency (-fill '#CCCCCC80' -opaque '#CCCCCC') like on the page
http://imagemagick.org/Usage/bugs/trans_bug/
and then conposite images
or you can use something like that

Code: Select all

convert test.jpg -matte -channel A -fx 0.5 test2.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Need help in creating a tranparency border

Post by Bonzo »

There is probably a better way to do this:

Code: Select all

convert -size 400x300 xc:blue blue_square.png

convert -size 400x300 xc:none -draw " fill black rectangle 50,50 350,250 " black_square.png

composite -compose Dst_Out black_square.png -gravity center blue_square.png -matte result_border.png 

composite -blend 88 -gravity center result_border.png sunflower.jpg -matte blue.jpg
First convert creates the background colour to be used in the border in this case blue
Second convert creates a mask which will be used to create the transparent area in the middle
First composite cuts the square out of the blue background leaving the blue border
Second coposite puts the border on top of the image changing its opacity

You need to cleanup and remove the tempory images
Post Reply