#38226 [Opn->Asn]: Patch for Bug 30863
| From: | tony2001@php.net | Date: | Wed, 26 Jul 2006 17:07:32 +0000 |
| Subject: | #38226 [Opn->Asn]: Patch for Bug 30863 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-99946@lists.php.net to get a copy of this message | ||
ID: 38226
Updated by: tony2001@php.net
Reported By: seth at pricepages dot org
-Status: Open
+Status: Assigned
Bug Type: GD related
Operating System: Mac 10.4
PHP Version: 5.1.4
-Assigned To:
+Assigned To: pajoye
Previous Comments:
------------------------------------------------------------------------
[2006-07-26 17:03:24] seth at pricepages dot org
Description:
------------
This small patch fixes the bug outlined in 30863
(http://bugs.php.net/bug.php?id=30863 ). The problem is a
one pixel shift of the transparency. A one pixel border on
one side remains the default color.
Caution: this fix strikes me as *too* simple. I'm worried
that I'm breaking something that I'm not noticing.
Original code (gd.c line ~1331):
/* If the pixel is transparent, we assign it the
palette index that
* will later be added at the end of the palette as
the transparent
* index. */
if ((oim->transparent >= 0) && (oim->transparent == *
(inptr - 1)))
{
*outptr++ = nim->colorsTotal;
inptr++;
continue;
}
Fixed code ("inptr - 1" changed):
/* If the pixel is transparent, we assign it the
palette index that
* will later be added at the end of the palette as
the transparent
* index. */
if ((oim->transparent >= 0) && (oim->transparent ==
(*inptr)))
{
*outptr++ = nim->colorsTotal;
inptr++;
continue;
}
In other news:
GD's quantization << pngquant
Maybe someday I'll port the code. Interest?
Reproduce code:
---------------
<?php
$img = imagecreatetruecolor(100,100);
//Start with a transparent canvas
$trans = imagecolorresolve($img, 255,255,255);
//Specifying a color as transparent (& below) causes the pixel shift
imagecolortransparent($img, $trans);
imagefilledrectangle($img, 0,0, 100,100, $trans);
//Make a solid grey box
$grey = imagecolorresolve($img, 128,128,128);
imagefilledrectangle($img, 0,50, 100,100, $grey);
//Draw a black line
$black = imagecolorresolve($img, 0,0,0);
imageline($img, 50,0, 50,100, $black);
//Converting to palette (& above) causes a pixel shift
imagetruecolortopalette($img, false, 256);
imagepng($img, 'test.png');
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38226&edit=1