#21668 [Opn->Csd]: imagecolorexact etc. not working for 8-bit paletted png
| From: | vrana@php.net | Date: | Tue, 27 Jul 2004 16:08:48 +0000 |
| Subject: | #21668 [Opn->Csd]: imagecolorexact etc. not working for 8-bit paletted png | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969362243@lists.php.net to get a copy of this message | ||
ID: 21668
Updated by: vrana@php.net
Reported By: phpbugs at dronkert dot net
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Win32 / OSF1
PHP Version: 4.2.3
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"If you created the image from a file, only colors used in the image
are resolved. Colors present only in the pallete are not resolved."
Previous Comments:
------------------------------------------------------------------------
[2003-01-15 13:31:23] phpbugs at dronkert dot net
I fail to see how that relates to this problem. The
imagecolorsforindex() function is not behaving unexpectedly: it returns
all 216 colours of the palette! Also, as you can see in my first
comment, both imagecolorclosest() and imagecolorresolve() do recognize
the palette (somewhat): they return a colour index of 215 and 214
respectively, not 0, 1 or 2 (<= no. of used colours). The fact that
they return different values also troubles me.
At best this is a documentation bug. The documentation does not
differentiate between colours actually used in the image, and colours
defined in the embedded palette. As I read it now, the functions
~exact(), ~closest() and ~resolve() should search/walk the palette
(like my code snippet does). However it seems as though they can only
return colours that are used in the image.
------------------------------------------------------------------------
[2003-01-15 13:02:43] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The color_index parameter for imagecolorsforindex() can be generated by
imagecolorat(). That function can only fetch the avaliable 3 colors of
the image, hence all other colors cannot be resolved regardless of the
palette.
This works the same way in GD 2.X bundled with PHP as it does with you
GD 1.8.4
------------------------------------------------------------------------
[2003-01-15 12:47:59] phpbugs at dronkert dot net
The image does indeed only contain (display) the 3 colours you mention.
The embedded palette however definitly defines 216 colours, as shown by
the output of test.php or:
for ( $i = 0; $i < imagecolorstotal( $im ); ++$i )
{
$c = imagecolorsforindex( $im, $i );
echo "$i = {$c['red']} {$c['green']} {$c['blue']}\n";
}
Corel Photopaint also shows me a 216-colour palette.
------------------------------------------------------------------------
[2003-01-15 12:34:09] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
According to my tests that image only contains 3 colors:
255,255,255
0, 0, 0
204, 204, 204
There is definately no 0,0,153 color.
------------------------------------------------------------------------
[2003-01-15 11:49:31] phpbugs at dronkert dot net
I created an 8-bit paletted png image using PHP, allocating the
complete webpalet 51*(r,g,b) with r,g,b in [0,5]. See
http://www.phys.uu.nl/~varsity/rowperfect/
- env.php only contains phpinfo().
- grid.php creates "grid.png" in the png subdir.
- test.php tries to analyze the colour palette.
As you can see the colour (0,0,153) definitely exists in the palette
and has index number 212. However, when searching for this colour
imagecolorexact() does not return a valid index value (-1) and
imagecolorclosest() returns the highest index number (215) which is
black (0,0,0). Even worse is imagecolorresolve(): it evidently picks
another index (214) and just replaces the existing colour at that
position with (0,0,153).
The behaviour is exactly the same on this webserver (OSF1, Apache
1.3.27, PHP 4.2.3, GD 1.8.4) as on my home system (Win2k, Apache
2.0.43, PHP 4.3.0-dev, GD 2 built-in). The png image
(http://www.phys.uu.nl/~varsity/rowperfect/png/grid.png) renders
faultless in IE6, Moz121, Corel Photopaint 9. If you want I can send
the grid.php/test.php source.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21668&edit=1