Bug #61221 [Ana->Csd]: imagegammacorrect function loses alpha channel
| From: | cmb@php.net | Date: | Wed, 17 Jun 2015 00:29:15 +0000 |
| Subject: | Bug #61221 [Ana->Csd]: imagegammacorrect function loses alpha channel | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193582@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61221&edit=1
ID: 61221
Updated by: cmb@php.net
Reported by: efbiaiinzinz at hotmail dot com
Summary: imagegammacorrect function loses alpha channel
-Status: Analyzed
+Status: Closed
Type: Bug
Package: GD related
Operating System: *
PHP Version: 5.6.9
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7469c7e7d0cee78abfaeeb087be494939bee82a9
Log: Fixed bug #61221 - imagegammacorrect function loses alpha channel
Previous Comments:
------------------------------------------------------------------------
[2015-06-06 13:34:57] cmb@php.net
Thanks for the confirmation regarding the patch, and sorry for
having had to wait so long. And, of course, thanks for your report
and the supplied test case.
I have submitted a respective PR now.
------------------------------------------------------------------------
[2015-06-06 08:56:48] efbiaiinzinz at hotmail dot com
Glad that someone finally discovered this issue after 3 years :)
Yes indeed, the original patch I did was made in a hurry and then forgotten.
Keeping the alpha value the same is correct behaviour and imagegammacorrect-alpha thus should work
correctly.
I wrote a PHP function to work around the issue at the time of the report, discovered the alpha
problem some time later in my code but didn't bother to add info here after a year or so total
silence from PHP team.
------------------------------------------------------------------------
[2015-06-06 00:47:31] cmb@php.net
I can still confirm the issue with current master (1123032) â even
when
imagesavealpha($img, true) is added to the supplied test
script, the alpha channel is lost when imagegammacorrect is
applied. I agree that this is a bug.
I'm in no way an expert on image manipulation, but I agree that
the alpha channel should not be modified in *any* *way* when
imagegammacorrect is called, i.e. the given patch should not be
applied, but rather imagegammacorrect-alpha.patch.
------------------------------------------------------------------------
[2015-06-06 00:45:35] cmb@php.net
The following patch has been added/updated:
Patch Name: imagegammacorrect-alpha
Revision: 1433551535
URL: https://bugs.php.net/patch-display.php?bug=61221&patch=imagegammacorrect-alpha&revision=1433551535
------------------------------------------------------------------------
[2013-07-02 10:17:50] efbiaiinzinz at hotmail dot com
In the original proposed patch, alpha shannel should not actually be modified by
imagegammacorrect, only rgb should get multiplied.
Sample test case to show alpha channel loss:
<?php
$imagew = 50;
$imageh = 50;
//truecolor means color allocations just combine ARGB into one integer value
$img = imagecreatetruecolor($imagew, $imageh);
//make sure alpha gets stored
imagesavealpha($img, true);
$blacktransparent = imagecolorallocatealpha($img, 0, 0, 0, 127);
$redsolid = imagecolorallocate($img, 255, 0, 0);
//fill with transparent black background
imagefill($img, 0, 0, $blacktransparent);
//draw solid red cross over the image for contrast
imageline($img, $imagew / 2, 0, $imagew / 2, $imageh - 1, $redsolid);
imageline($img, 0, $imageh / 2, $imagew - 1, $imageh / 2, $redsolid);
//execute imagecammacorrect with same input-/output gamma values so that colors
should actually remain same
imagegammacorrect($img, 1, 1);
//ask top-left corner color, for truecolor it is ARGB combined into one integer
value
$color = imagecolorat($img, 0, 0);
//correct result should be same black-based transparent color that we used for
filling
echo $color === $blacktransparent ? 'ok' : 'failure';
//comment the echo line above and uncomment the two lines below to see visually
how transparent color gets changed to solid black
//header('Content-Type: image/png');
//imagepng($img);
imagedestroy($img);
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61221
--
Edit this bug report at https://bugs.php.net/bug.php?id=61221&edit=1