Transparent annotate + transparent 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
Andy
Posts: 30
Joined: 2014-03-23T03:06:04-07:00
Authentication code: 6789

Transparent annotate + transparent border

Post by Andy »

Hi,

as the title suggest, i want to draw a text with a border where each, the text color + transparency and the border color + transparency can be adjusted independently.

first attempt:

Code: Select all

convert -size 500x500 xc:transparent -gravity center -font Impact -pointsize 60 -fill "rgba(255,255,255,0.58)" -stroke  "rgba(0,0,0,1)" -strokewidth 4.000 -annotate +0+0 "TESTTEXT"  -trim test.png
This does not work as expected. The text color is somehow influenced by the border color. The end result does not have the correct transparency nor color.

So my idea was to create a text for the border only, without "fill" and add an other text without the border afterwards, like this:

Code: Select all

convert -size 500x500 xc:transparent -gravity center -font Impact -pointsize 60 -fill none -stroke "rgba(0,0,0,1)" -strokewidth 4.000 -annotate +0+0 "TESTTEXT" -font Impact -pointsize 60 -fill "rgba(255,255,255,0.58)" -stroke none -strokewidth 4.000 -annotate +0+0 "lkhnl"  -trim test.png
This works a little bit better. The transparency seems to be correct but the border overlaps the actual text which makes it look pretty bad.

So my next idea would be to cut the actual text from the border "layer" first, so the overlapping border part would be removed.
Could someone give me a hint how to do that? Couldn't find anything about "cutting text from an image"

Other suggestions would be welcomed as well.

Regards
Andy
Posts: 30
Joined: 2014-03-23T03:06:04-07:00
Authentication code: 6789

Re: Transparent annotate + transparent border

Post by Andy »

I found a solution myself.

I just paint the text a second time with -fill none AND -stroke none. Like this:

Code: Select all

convert -size 500x500 xc:transparent -gravity center 
-font Impact -pointsize 60 -fill none -stroke "rgba(0,0,0,1)" -strokewidth 4.000 -annotate +0+0 "TESTTEXT" 
-font Impact -pointsize 60 -fill none -stroke none -strokewidth 4.000 -annotate +0+0 "TESTTEXT" 
-font Impact -pointsize 60 -fill "rgba(255,255,255,0.58)" -stroke none -strokewidth 4.000 -annotate +0+0 "TESTTEXT"  
-trim test.png
This erases the overlapping text first and then paints the text in the correct color.

Greetings
Andy
Posts: 30
Joined: 2014-03-23T03:06:04-07:00
Authentication code: 6789

Re: Transparent annotate + transparent border

Post by Andy »

Hi again,

i am back to zero. I cannot use the way mentioned above (annotate), I need to use labels to get the auto generated canvas size.

convert -background transparent -interline-spacing -24.78 -gravity West -font Great-Vibes -pointsize 70
\( -fill transparent -stroke "rgba(0,0,0,1)" -strokewidth 1.200 label:"TESTTEXT" \)
\( -fill transparent -stroke none -strokewidth 1.200 label:"TESTTEXT" \)
-fill "rgba(255,207,250,1)" -stroke none -strokewidth 1.200 label:"TESTTEXT"
-layers merge +repage test.png

I got this far but the extra step to delete the overlapping border does no work with labels. My guess is that labels are not able to write transparent text over already existing text and make it disappear like that.

How do i remove the overlapping inner border when using labels?

Best regards
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transparent annotate + transparent border

Post by snibgo »

IM has a border feature that you haven't used, so I don't understand your questions. Perhaps where you have written "border" you mean "stroke", which is the outline of the characters.
... are not able to write transparent text over already existing text and make it disappear like that.
If you write semi transparent pixels over some other pixels, those other pixels are still somewhat visible. That's how transparency works. If you view something through a semi-transparent sweet wrapper, you can still see that something, but in a slightly different colour.
snibgo's IM pages: im.snibgo.com
Andy
Posts: 30
Joined: 2014-03-23T03:06:04-07:00
Authentication code: 6789

Re: Transparent annotate + transparent border

Post by Andy »

You are right, i was talking about "stroke".

Could you have a look at my second post. That does exactly what i need, including the removal of the unnecessary overlap by using "-fill none -stroke none" but the canvas size is not the one i need because i have to use -trim.

I want to achieve the same with labels if possible. I don't really care if I am using "transparency" or i cut the text out somehow.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Transparent annotate + transparent border

Post by GeeMack »

Andy wrote: 2017-07-23T12:10:17-07:00I got this far but the extra step to delete the overlapping border does no work with labels. My guess is that labels are not able to write transparent text over already existing text and make it disappear like that.
There are only a few situations where IM can write or draw with a fill of "none" to make the existing image transparent in those areas. To get what you want you may need to create two labels, one with a stroke and one without, and composite the not-stroked one onto the stroked one with an appropriate compose method. This is an example of how to make that work...

Code: Select all

convert -background none -pointsize 50 -strokewidth 6 \
   -stroke black -fill black label:"THIS IS A TEST" \
   -stroke none -fill white label:"THIS IS A TEST" -compose dstout -composite output.png
Edited to add: In that example you should be able to adjust the transparency of the stroke when you create that first label by designating its color to include some amount of alpha transparency. After the "-composite" you'll have a semi-transparent stroke with what amounts to a fully transparent fill. To also achieve a semi-transparent fill you'll need to make one more label and composite it over the result of the first output. Something like this should get you toward the result you described in your opening post...

Code: Select all

convert -background none -pointsize 50 -strokewidth 6 \
   -stroke \#00000040 -fill black label:"THIS IS A TEST" \
   -stroke none -fill white label:"THIS IS A TEST" -compose dstout -composite \
   -fill \#FF000080 label:"THIS IS A TEST" -compose over -composite output.png
That will produce a label with a semi-transparent (25% opaque) black stroke around a semi-transparent (50% opaque) red fill. I put this together in a bash shell using IM 6.7.7-10. It should also work on anything newer.
Andy
Posts: 30
Joined: 2014-03-23T03:06:04-07:00
Authentication code: 6789

Re: Transparent annotate + transparent border

Post by Andy »

That worked like a charm, thx a lot GeeMack.
Post Reply