Page 1 of 1

[Solved] Add padding to a label with translucent background

Posted: 2016-09-07T02:17:56-07:00
by sas
When using a solid background color, I can add padding to a label like this:

Code: Select all

color="#0000ff"
convert -size 100x -background "$color" label:"Hello" -bordercolor "$color" -border 20x20 label.png
Image

But when using a translucent background color like...

Code: Select all

color="rgba(0,0,255,0.5)"
...then the inner area for some reason gets the background color blended in twice:
Image

Adding -background none just before the -border command doesn't help.

What's the correct way to it?

(This is with ImageMagick 7.0.3-0 Q32 x86_64 2016-09-07 on Linux.)

Re: [IM7] Add padding to a label with translucent background

Posted: 2016-09-07T02:28:19-07:00
by sas
OK, I managed to find a solution:

Code: Select all

color="rgba(0,0,255,0.5)"
convert -size 100x -background none label:"Hello" -bordercolor none -border 20x20 -background "$color" -flatten label.png
Image

However, I'd still like to know why the behavior shown in the previous post (double-blended background color in the inner rectangle) occurs.

Re: [IM7] Add padding to a label with translucent background

Posted: 2016-09-07T03:16:14-07:00
by snibgo
An alternative to do what you want is to insert "-compose atop" before "-border".

The confusion is that "-border" doesn't simply add a border. It makes a canvas of the total size, in the requested bordercolor, and composites the image on it. See http://www.imagemagick.org/script/comma ... php#border

Re: [IM7] Add padding to a label with translucent background

Posted: 2016-09-07T03:25:38-07:00
by sas
@snibgo: With atop the result isn't quite right, either:

Code: Select all

color="rgba(0,0,255,0.5)"
convert -size 100x -background "$color" label:"Hello" -bordercolor "$color" -compose atop -border 20x20 label.png
Image

Re: [IM7] Add padding to a label with translucent background

Posted: 2016-09-07T03:59:53-07:00
by snibgo
You are correct. I meant "-compose copy", not "-compose atop". Sorry about that.

Re: [IM7] Add padding to a label with translucent background

Posted: 2016-09-07T04:13:23-07:00
by sas
With copy it works:
Image

Thanks for the help.