ID:               38226
 Updated by:       [EMAIL PROTECTED]
 Reported By:      seth at pricepages dot org
-Status:           Assigned
+Status:           Feedback
 Bug Type:         GD related
 Operating System: Mac 10.4
 PHP Version:      5.1.4
 Assigned To:      pajoye
 New Comment:

Please provide an unified diff (diff -up) and a link to it.



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

Reply via email to