[Solved] Using alpha of programmatically generated image for clipping mask of RGBA background color label?
Posted: 2019-09-15T21:06:04-07:00
I've been experimenting with an IM label all-in-one command that produces a rounded corner image based on the dimensions of a text label and wanted to use the result as a kind of clipping mask for the subsequent visible text label and RGBA background color (the initial text label is simply used to set the dimensions for the rounded corner mask).
The nice thing about IM is so far this can all be done without writing to temporary files, with the help of command parentheses.
I have a functioning workaround (posted in the code at the bottom) which separates the color background fill color and then changes the opacity of rounded corner mask to create the same effect (since I'm not really that familiar with IM so parts are taken from useful docs examples) but the purpose of this topic is to ask if there's a way to instead allow for the final background fill to be defined as a single RGBA value while using the alpha image of the rounded corners as a kind of clipping mask. This would allow me to simplify the background color to a single variable for a script I have in mind.
A visual representation of the desired effect (the 'Goal' background is 70% opacity):
What I have so far
The generated rounded corner image (here edited to output to an external file for the sake of this topic):
My current functioning workaround that separates the final background color and changes the opacity of the rounded corner alpha:
Note: the parentheses above are escaped for Windows CMD.exe use. They will likely have to be escaped differently for other OSes or console programs.
The nice thing about IM is so far this can all be done without writing to temporary files, with the help of command parentheses.
I have a functioning workaround (posted in the code at the bottom) which separates the color background fill color and then changes the opacity of rounded corner mask to create the same effect (since I'm not really that familiar with IM so parts are taken from useful docs examples) but the purpose of this topic is to ask if there's a way to instead allow for the final background fill to be defined as a single RGBA value while using the alpha image of the rounded corners as a kind of clipping mask. This would allow me to simplify the background color to a single variable for a script I have in mind.
A visual representation of the desired effect (the 'Goal' background is 70% opacity):
What I have so far
The generated rounded corner image (here edited to output to an external file for the sake of this topic):
Code: Select all
magick -background "#FFFFFF" -fill "#FFFFFF" -font "Segoe-UI-Semibold" -pointsize "15" label:"Text String" -gravity southeast -splice 6x4 -gravity northwest -splice 6x2 ^( +clone -alpha extract -draw " fill black polygon 0,0 0,2 2,0 fill white circle 2,2 2,0" ^( +clone -flip ^) -compose Multiply -composite ^( +clone -flop ^) -compose Multiply -composite ^) -alpha off -compose CopyOpacity -composite -channel a -evaluate divide 1 output.png
Code: Select all
magick -background "#3399FF" -fill "#F26322" -font "Segoe-UI-Semibold" -pointsize "15" label:"Text String" -gravity southeast -splice 6x4 -gravity northwest -splice 6x2 ^( -background "#FFFFFF" -fill "#FFFFFF" -font "Segoe-UI-Semibold" -pointsize "15" label:"Text String" -gravity southeast -splice 6x4 -gravity northwest -splice 6x2 ^( +clone -alpha extract -draw " fill black polygon 0,0 0,2 2,0 fill white circle 2,2 2,0" ^( +clone -flip ^) -compose Multiply -composite ^( +clone -flop ^) -compose Multiply -composite ^) -alpha off -compose CopyOpacity -composite -channel a -evaluate divide 1.42 ^) -compose CopyOpacity -composite output.png