Home  |  Linux  | Mysql  | PHP  | XML
From:Pierre Joye Date:Wed May  7 01:05:02 2008
Subject:Re: [GD-DEVEL] Newbie transparent gif question- possibly solved.
Hi Roger.

On Tue, May 6, 2008 at 11:25 PM, Roger Oberholtzer <roger@opq.se> wrote:
>
>  On Tue, 2008-05-06 at 17:40 +0200, Pierre Joye wrote:
>  > On Tue, May 6, 2008 at 5:29 PM, Roger Oberholtzer <roger@opq.se> wrote:
>  >
>  > >  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.
>  >
>  > Either I'm getting bad at explaining things or you focus way too much
>  > on the RGB values instead of the main ideas behind palette images:
>  > Indexed colors :)
>
>  Perhaps the problem is my description. I too am focused on indexes. If
>  indexes were not used, my original problem would not have occurred.
>
>
>  > >  > >  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.
>  >
>  > Again (sigh), RGB values in palette images are completely irrelevant,
>  > GD uses the indexes. But yes, a sample code will help me to help you
>
>  In GD, if I Allocate the same color multiple times using the same RGB
>  values, I would obtain more than one index for the same color. And I
>  could use any of those indexes interchangeably to draw the color to
>  which the indexes refer.

That's not how it works. It only takes care of the indexes, not the values.

> Visibly these colors will look the same, even
>  though they are using different indexes into the color map. But only one
>  index can be defined to be transparent. If you are unlucky and Allocate
>  and use the colors and define the transparent color in a specific
>  sequence - there will be no transparency. BECAUSE of the use of indexes.

And that's not going to change. It is how it works in PNG and GIF
formats too. If you like to allocate a color and be sure that you do
not allocate the same color twice, use one of these functions:
 gdImageColorResolve or gdImageColorClosest (and their alpha equivalent).

Now if you don't want to have to think about indexes, why don't use
true color images?

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org
Navigate in group php.gd.devel at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants