php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38226 Patch for Bug 30863
Submitted: 2006-07-26 17:03 UTC Modified: 2006-07-26 18:38 UTC
From: seth at pricepages dot org Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 5.1.4 OS: Mac 10.4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: seth at pricepages dot org
New email:
PHP Version: OS:

 

 [2006-07-26 17:03 UTC] 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');
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-26 18:36 UTC] pajoye@php.net
Please provide an unified diff (diff -up) and a link to it.

 [2006-07-26 18:38 UTC] pajoye@php.net
also #30863 was clearly bogus and a solution was provided. If you think it is not and have arguments (images and reproduce codes), please post the patch there. I close this bug, one report for one bug :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 10:00:02 2025 UTC