Bug #61221 [PATCH]: imagegammacorrect function loses alpha channel

From: Date: Sat, 06 Jun 2015 00:45:36 +0000
Subject: Bug #61221 [PATCH]: imagegammacorrect function loses alpha channel
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193163@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 Patch added by: cmb@php.net Reported by: efbiaiinzinz at hotmail dot com Summary: imagegammacorrect function loses alpha channel Status: Open Type: Bug Package: GD related PHP Version: 5.4.0RC8 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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); ------------------------------------------------------------------------ [2012-03-01 14:56:41] efbiaiinzinz at hotmail dot com Description: ------------ When issuing imagegammacorrect function on an image resource that has alpha channel, the alpha channel gets lost. I looked at the source of 5.4.0RC8 and have also made a minor patch that adds alpha channel support by modifying the ext/gd/gd.c file. Test script: --------------- $img = imagecreatefrompng('input.png'); imagegammacorrect($img, 1.0, 1.0); imagepng($img, 'result.png'); Expected result: ---------------- I would expect to see output.png retain its alpha channel. Actual result: -------------- The result file does not have any transparency, since the current source code indeed does not do gamma correction to alpha channel. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61221&edit=1

« previous php.bugs (#193163) next »