|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 03:00:02 2025 UTC |
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