[TYPO3-core] RFC: GIFBUILDER transparency

Bernhard Kraft kraftb at kraftb.at
Fri Mar 17 18:41:12 CET 2006


Franz Holzinger wrote:
>>-        $retCol = false;
>>+        $retCol = -1;
> 
> 
> You have changed the interface here. This can be a break in
> compatibility for extensions using unifyColors.

This method was newly introduced with my GIFBUILDER patch. Previously it was not possible to
have more than one transparent color. Now it is possible :) As this can't be achieved by setting
multiple transparent colors (png and gif don't support this) i solved it by "unifying" the colors
to be transparent into one color (the first to be transparent) and just set this as only transparent
color.
I had to set it to -1 because else the method would return two different kind of values (integer for
color index boolean false for not found).
and as the method returns an color index I found it was wrong to return false because this evaluates
as 0 which is also a valid color index (-1 == color not found after the php docs)


> I do not understand what $this->png_truecolor is used in this context.If
> $this->png_truecolor == 0 then $this->truecolor will be deleted also for
> GIFs. However from the IF above in the patch I can see that it must be
> possible to have $this->truecolor==1 and $this->png_truecolor == 0 at
> the same time. Or an && has to be joined with !$this->png_truecolor here.
> 
> 
> 
>>+                // Transparency does not properly work when, GIFs or
>>8-bit PNGs are generated or reduceColors is set -- disable truecolor
>>flag so they get generated "natively" in 8-bit.
>>+                // not working with reduceColors and truecolor images
>>+            if (($this->setup['transparentBackground'] ||
>>is_array($this->setup['transparentColor_array'])) &&
>>($this->gifExtension=='gif' || !$this->png_truecolor ||
>>isset($this->setup['reduceColors'])))    {
>>+                $this->truecolor = false;
>>+            }

The first part of this if condition is:

($this->setup['transparentBackground'] || is_array($this->setup['transparentColor_array']))

So setting truecolor=false will only occur when one of those options is set.
Which directly brings us to your next question:

>>$Bcolor = ImageColorExact($this->im, $BGcols[0],$BGcols[1],$BGcols[2]);
> 
> 
> I have read that this would not work with pngs with more than 256 colors.
> http://de.php.net/manual/fr/function.imagecolorexact.php
> 
> Maybe an if should come around it so only ImageMagick versions who have
> an error here will use this extra function call.

The "if" from the previous condition set's truecolor=false (there WILL be only 256 colors) when transparency
is used. And the line you are worrying about here:

 >>$Bcolor = ImageColorExact($this->im, $BGcols[0],$BGcols[1],$BGcols[2]);

fetches the color index for the transparent color ... so only get's executed when one of the transparent
properties from the if condition is true.

The second part of the above if condition matches the cases where truecolor isn't allowed.
This is the case when:
a) a gif get's generated (would result in bad colors cause they will have to get reduced to 256)
b) png_truecolor is not set - png_truecolor is an "output" setting which only decides if the final
output shall be truecolor. (if not set would result in bad colors because reduced ..)
c) reduceColors is set.

For this cases ->truecolor gets clered which disables internal rendering in truecolor.




greets,
Bernhard



More information about the TYPO3-team-core mailing list