#38226 [NEW]: Patch for Bug 30863
| From: | seth at pricepages dot org | Date: | Wed, 26 Jul 2006 17:03:24 +0000 |
| Subject: | #38226 [NEW]: Patch for Bug 30863 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-99945@lists.php.net to get a copy of this message | ||
From: seth at pricepages dot org
Operating system: Mac 10.4
PHP version: 5.1.4
PHP Bug Type: GD related
Bug description: Patch for Bug 30863
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 bug report at http://bugs.php.net/?id=38226&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38226&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38226&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38226&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38226&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=38226&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38226&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38226&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38226&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38226&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38226&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=38226&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=38226&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38226&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38226&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38226&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38226&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38226&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38226&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38226&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38226&r=mysqlcfg