php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28949 imagetruecolortopalette - colors in palette are missing and filled with white
Submitted: 2004-06-28 18:27 UTC Modified: 2004-08-10 01:00 UTC
Votes:7
Avg. Score:4.6 ± 0.5
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:5 (71.4%)
From: vkary at web dot de Assigned:
Status: No Feedback Package: GD related
PHP Version: 4.3.7 OS: WinXP & Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-06-28 18:27 UTC] vkary at web dot de
Description:
------------
When trying to reduce a true color image to a palette image with for example 16 or 32 colors, many colors are missing from the palette and filled with white color instead.

Reproduce code:
---------------
<?php
$src_im = imagecreatefromjpeg ("ara.jpg");

imagetruecolortopalette ($src_im, false, 16);

Header("Content-type: image/png");
imagepng($src_im);
?>

Expected result:
----------------
The color palette should have exactly the number of colors specified in imagetruecolortopalette (16 for example) an the color reduced image should look like this:(created with PHP 4.3.2, GD-Lib 2.0.12)

http://www.textilenetwork.de/php/ara16_4_3_2.png

The color palette for the image above:

http://www.textilenetwork.de/php/ara16_4_3_2_pal.png

or for 32 colors:

http://www.textilenetwork.de/php/ara32_4_3_2.png
http://www.textilenetwork.de/php/ara32_4_3_2_pal.png


Actual result:
--------------
The images and color palettes with PHP 4.3.6: (& PHP 4.3.7)

http://www.textilenetwork.de/php/ara16_4_3_6.png
http://www.textilenetwork.de/php/ara16_4_3_6_pal.png

http://www.textilenetwork.de/php/ara32_4_3_6.png
http://www.textilenetwork.de/php/ara32_4_3_6_pal.png


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-03 11:58 UTC] vkary at web dot de
I have found a difference between the PHP 4.3.2 and PHP 4.3.7 in the file "gd_topal.c"

gd_topal.c, PHP 4.3.2, lines 733-742
-------------------------------------

#ifdef ORIGINAL_LIB_JPEG
	cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total >> 1)) / total);
	cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total >> 1)) / total);
	cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total >> 1)) / total);
#else
	im->red[icolor] = (int) ((c0total + (total >> 1)) / total);
	im->green[icolor] = (int) ((c1total + (total >> 1)) / total);
	im->blue[icolor] = (int) ((c2total + (total >> 1)) / total);
#endif
}


gd_topal.c, PHP 4.3.7, lines 733-748
-------------------------------------

#ifdef ORIGINAL_LIB_JPEG
	cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total >> 1)) / total);
	cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total >> 1)) / total);
	cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total >> 1)) / total);
#else
	/* 2.0.16: Paul den Dulk found an occasion where total can be 0 */
	if (count) {
		im->red[icolor] = (int) ((c0total + (total >> 1)) / total);
		im->green[icolor] = (int) ((c1total + (total >> 1)) / total);
		im->blue[icolor] = (int) ((c2total + (total >> 1)) / total);
	} else {
		im->red[icolor] = 255;
		im->green[icolor] = 255;
		im->blue[icolor] = 255;
	}
#endif
 [2004-07-03 12:16 UTC] vkary at web dot de
...and another difference:

A few lines above, the variable "count" is initialized with "0"
 [2004-07-14 12:55 UTC] service at textilenetwork dot de
This bug still exists in release of PHP 5!
 [2004-07-23 13:24 UTC] vkary at web dot de
BOUTELL.COM:
-------------
"07/21/04: gd 2.0.28 has been released. gd 2.0.28 restores support for reading and writing GIF images. There is also a fix for a possible problem in gdImageTrueColorToPalette."
 [2004-08-02 11:18 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2004-08-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2014-05-22 10:49 UTC] icp at freigre dot com
This bug is still active in PHP 5.5, please fix it.
imagetruecolortopalette is essential for creating small-filesized PNGs and GIFs!
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC