Re: [GD-DEVEL] Newbie transparent gif question- possibly solved.
| From: | Roger Oberholtzer | Date: | Tue, 06 May 2008 15:29:12 +0000 |
| Subject: | Re: [GD-DEVEL] Newbie transparent gif question- possibly solved. | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-432@lists.php.net to get a copy of this message | ||
On Tue, 2008-05-06 at 14:33 +0200, Pierre Joye wrote:
> 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).
So you agree. Granted, the coding here is perhaps not what should be
done. But it does demonstrate a red image with red set to be the
transparent color - that will not have a transparent background. This
code is obviously incorrect in execution, if not in intention.
> > 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.
I will re-break my program and provide you with one. This is more what I
was doing at the beginning of all my problems. I would make a new image
and define a transparent color as the first color, and save it to a
file. I would then read in the file and once again define (Allocate) the
same RGB values as a color and make it the transparent color - just as I
had done when I first made the image. At which time, my transparency
vanished.
--
Roger Oberholtzer
OPQ Systems / Ramböll RST
Ramböll Sverige AB
Kapellgränd 7
P.O. Box 4205
SE-102 65 Stockholm, Sweden
Office: Int +46 8-615 60 20
Mobile: Int +46 70-815 1696