Re: [GD-DEVEL] Newbie transparent gif question- possibly solved.
| From: | Pierre Joye | Date: | Tue, 06 May 2008 12:33:06 +0000 |
| Subject: | Re: [GD-DEVEL] Newbie transparent gif question- possibly solved. | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-431@lists.php.net to get a copy of this message | ||
Hi,
On Tue, May 6, 2008 at 2:11 PM, Roger Oberholtzer <roger@opq.se> wrote:
> > That's not correct. It works as expected by using a color index (not a
> > color value!) for palette images and a color value for true color
> > images.
>
> Put two instances of the same color in the color map. Set the
> transparent color to the first one. Use the second in the actual
> drawing. You will not get a transparent image:
>
> # new file
> red = gdImageColorAllocate(im, 255,0,0);
> red = gdImageColorAllocate(im, 255,0,0);
> gdImageColorTransparent(im, red);
> # save file
>
> The image background will be set to the first red (color map index 0).
> The transparent color will be index 1. The image will not be
> transparent.
The background will be red (index 0). Why? the image buffer is zero'ed
when you create a new image. That's why the very first allocated color
(which incidently has the index 0) will be the background color.
Then you tell GD to use the index 1 as transparent color. As one is
not equal to zero, you will not get a transparent image. Remember that
it uses the *index* not the color value to detect if a pixel should be
treated as the transparent color (index).
> Read in a file that already contains red and has that as the background
> color, and do this:
>
> # read file
> red = gdImageColorAllocate(im, 255,0,0);
> gdImageColorTransparent(im, red);
> # save file
>
> The background will no longer be transparent. Even it it was when you
> read the file.
Please provide a file showing this case.
> Your sample code is suspect for palette images:
>
>
> im = gdImageCreate(100,100);
> for (i=0; I<256;i++) {
> a[i] = gdImageColorAllocate(im, 255,0,0);
> }
> gdImageColorTransparent(im, 23);
>
>
> What would the background color be? Index 0 (the first defined color).
> What would the transparent color be? 23, not 0. Color map item 23 is
> not the background color. The image background will not be transparent.
Exactly, and that's expected.
Cheers,
--
Pierre
http://blog.thepimp.net | http://www.libgd.org