Bug #68629 [NEW]: Transparent artifacts when using imagerotate

From: Date: Fri, 19 Dec 2014 14:12:56 +0000
Subject: Bug #68629 [NEW]: Transparent artifacts when using imagerotate
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189129@lists.php.net to get a copy of this message
From:             bas5winkel at gmail dot com
Operating system: Windows7
PHP version:      5.5Git-2014-12-19 (Git)
Package:          GD related
Bug Type:         Bug
Bug description:Transparent artifacts when using imagerotate

Description:
------------
---
From manual page: http://www.php.net/function.imagerotate
---

Linux (RHEL6+PHP5.3.3) works fine.
But with WAMP (Windows7+PHP5.5.12) transparent artifacts appear when
using imagerotate.
The artifacts appear only in the transparent area of the image that is
rotated.
The transparent aera should only contain pixels with the color code
0X7F000000 but a 'grid'-like pattern of pixels with color code
0x7E000000 appears.
(the alpha channel value should be 127 but some pixels become 126).
In the test script I have replaced the incorrect pixels with a non
transparent color to show the pattern.



Test script:
---------------
<?PHP

// create fully transparent canvas
$canvas = imagecreatetruecolor(200,200);
imagesavealpha($canvas, true);
$trans_colour = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
imagefill($canvas, 0, 0, $trans_colour); 
imagesavealpha($canvas, true);

// rotate the canvas 45 degrees
$outputCanvas = imagerotate($canvas, 45,
imageColorAllocateAlpha($canvas, 0, 0, 0, 127),0);
imagealphablending($outputCanvas, false);
imagesavealpha($outputCanvas, true);
	
// replace colors not being fully transparent
$blue_color = imageColorAllocateAlpha($outputCanvas, 0, 0, 255, 0);
$width = imagesx($outputCanvas);
$height = imagesy($outputCanvas);
for($y=0;$y<$height;$y++)
{
	for($x=0;$x<$width;$x++)
	{
		$rgb = imagecolorat($outputCanvas, $x, $y);
		if ($rgb != 0x7F000000)
		{
			imagesetpixel($outputCanvas,$x,$y,$blue_color);
		}
	}
}

header("Content-Type: image/png");
imagepng($outputCanvas);

imagedestroy($canvas);
imagedestroy($outputCanvas);
		
?>

Expected result:
----------------
The script rotates a fully transparent image and should show a fully
transparent image (shown as a grey image in most browsers).
Pixels that are not fully transparent are colored blue.
No blue pixels should be visible.

Actual result:
--------------
When running the script on windows7 (wamp2.5-PHP5.5.12),
a grid like grey/blue pattern appears which shows that most fully
transparent pixels have become not fully transparent during the
rotation.
I replaced the pixels that are not correct with a blue color in order to
visualize the pattern. 
All pixels should have a alpha value of 127 but somehow most of them
become 126.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=68629&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68629&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68629&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68629&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68629&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68629&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68629&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68629&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68629&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68629&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68629&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68629&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68629&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68629&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68629&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68629&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68629&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68629&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68629&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68629&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68629&r=mysqlcfg



Thread (8 messages)

« previous php.bugs (#189129) next »