Re: [GD-DEVEL] Rendering Transparent Text?

[email protected] (Jason Young) Tue, 18 Aug 2009 21:23:14 -0400
Newsgroups php.gd.devel
Message-ID <[email protected]>
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 <[email protected]> wrote:
>> On Sat, Dec 20, 2008 at 9:56 PM, Rob Zimmerman <[email protected]> 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 <[email protected]> wrote:
>> On Sat, Dec 20, 2008 at 9:56 PM, Rob Zimmerman <[email protected]> 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
>>
> 
> 
>