Re: [GD-DEVEL] Rendering Transparent Text?
| From: | Jason Young | Date: | Wed, 19 Aug 2009 01:23:14 +0000 |
| Subject: | Re: [GD-DEVEL] Rendering Transparent Text? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-596@lists.php.net to get a copy of this message | ||
Whatever happened to this thread? Pierre's last message did not contain an attachment, and I still can't seem to get this to work. Don't know if Pierre's proposed patch ever made it into release..
Consider the following code:
<?php
$im = imagecreatetruecolor(20, 25);
$font = 'verdana.ttf';
$blue = imagecolorallocate($im, 0, 0, 255);
$green = imagecoloralloacte($im, 0, 255, 0);
$trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $blue);
imagefill($im, 0, 0, $green);
imagettftext($im, 12, 0, 0, 20, $trans, $font, '?');
?>
Expected result (as the parent poster had asked for) would essentially be a green image with a blue question mark - the idea being the transparency 'eats through' the layer, exposing what's underneath.
However, this is not so, I get black.
I have tried all manners and combinations of imagesavealpha and/or imagealphablending to no avail.
Is there any way of doing this? I'd like to use this trick as a cheap (only?) way to render gradients or other patterns in my text.
Thanks for any help, I'd like to see this thread come back and be resolved. :)
-Jason
Pierre Joye wrote:
hi, I have something that could be seen as a fix. The idea is the following: if alpha blending is disabled and the foreground color has an alpha value of 127 (transparent) then the text is rendered using only the alpha value (a kind of erasing mode). An example result is attached. Comments/other ideas welcome, On Sun, Dec 21, 2008 at 12:06 AM, Pierre Joye <pierre.php@gmail.com> wrote:On Sat, Dec 20, 2008 at 9:56 PM, Rob Zimmerman <sgreth@gmail.com> wrote:I need the anti-aliasing and as Colen pointed out you'll lose that unless you write a drawing primitive.I understood and the examples I gave have the anti aliasing. What I asked is how have you tried it as imagecolortransparent has nothing to do with the alpha channel. In the mean time I gave it a try, and there is a bug. It should be to draw a text using a color with a 100% alpha channel. For now it draws the bounding boxes of each glyph and not the glyph itself. I will fix that asap. Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org
hi, I have something that could be seen as a fix. The idea is the following: if alpha blending is disabled and the foreground color has an alpha value of 127 (transparent) then the text is rendered using only the alpha value (a kind of erasing mode). An example result is attached. Comments/other ideas welcome, On Sun, Dec 21, 2008 at 12:06 AM, Pierre Joye <pierre.php@gmail.com> wrote:On Sat, Dec 20, 2008 at 9:56 PM, Rob Zimmerman <sgreth@gmail.com> wrote:I need the anti-aliasing and as Colen pointed out you'll lose that unless you write a drawing primitive.I understood and the examples I gave have the anti aliasing. What I asked is how have you tried it as imagecolortransparent has nothing to do with the alpha channel. In the mean time I gave it a try, and there is a bug. It should be to draw a text using a color with a 100% alpha channel. For now it draws the bounding boxes of each glyph and not the glyph itself. I will fix that asap. Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org