Hello magicians,
I am trying to generate text with alpha bg ('#00000080') and then make it rounded.
But all of the examples from https://www.imagemagick.org/Usage/thumbnails/#rounded messes up with the alpha chanell and the result does not looks nice.
Any ideas to achieve this ?
TEXTBOX with alpha background and rounded corners
Re: TEXTBOX with alpha background and rounded corners
What version of imagemagick are you using and what command?
Re: TEXTBOX with alpha background and rounded corners
Version: ImageMagick 7.0.8-7 Q16 x86_64 2018-07-24
I generate the text with:
convert -size 800x -background '#00000080' -fill white -pointsize 24 pango:@./text.txt text.png
And then I have tried to make it rounded with all of the examples from: https://www.imagemagick.org/Usage/thumbnails/#rounded
For example:
convert text.png \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite rounded_corners.png
I generate the text with:
convert -size 800x -background '#00000080' -fill white -pointsize 24 pango:@./text.txt text.png
And then I have tried to make it rounded with all of the examples from: https://www.imagemagick.org/Usage/thumbnails/#rounded
For example:
convert text.png \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite rounded_corners.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: TEXTBOX with alpha background and rounded corners
Post your text.png image, so we can test your rounded corner command. Note that ImageMagick 7 uses magick in place of convert. If your text image has transparency, then you likely need to save the alpha channel and then after making the rounded corners, combine it with the new alpha channel in the rounded_corners.png. The alpha off in your command is turning the transparency in your text.png image off and then adding only transparency for the rounded corners.
Try this:
If that works, then replace my text.png with yours.
Try this:
Code: Select all
convert -size 300x300 -background "#00000080" -font ubuntu -fill white -gravity center caption:"This is the time for all good men to come to the aid of their country" text.png
convert text.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
\( +clone -alpha opaque -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
mpr:alpha -compose multiply -composite \
\) -alpha off -compose CopyOpacity -composite rounded_corners.png
If that works, then replace my text.png with yours.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: TEXTBOX with alpha background and rounded corners
I don't know if you're locked into that particular sequence, but if not, I'd consider taking a somewhat different approach. With a single command you can create the text caption on a transparent background, create a rounded-corner, semi-transparent background image, and composite the text over that background. A command would look something like this..._merlim_ wrote: ↑2018-07-30T05:15:44-07:00I generate the text with: [...]
And then I have tried to make it rounded with all of the examples from: https://www.imagemagick.org/Usage/thumbnails/#rounded
Code: Select all
convert -size 300x300 -background none -gravity center \
xc:none -fill '#00000080' -draw 'roundrectangle 0,0 299,299 15,15' \
-fill white caption:"This is the time for all good men to come to the aid of their country" \
-composite rounded_corners.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: TEXTBOX with alpha background and rounded corners
Nice clean approach, GeeMack!
Re: TEXTBOX with alpha background and rounded corners
Nedless to say, both solutions were magic.
Thank you!
Thank you!