Skip to content

Commit 7469c7e

Browse files
committed
Fixed bug #61221 - imagegammacorrect function loses alpha channel
When applying imagegammacorrect() the alpha channel is now fully retained, instead of being completely lost.
1 parent 5583421 commit 7469c7e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ext/gd/gd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,10 +3045,11 @@ PHP_FUNCTION(imagegammacorrect)
30453045
for (x = 0; x < gdImageSX(im); x++) {
30463046
c = gdImageGetPixel(im, x, y);
30473047
gdImageSetPixel(im, x, y,
3048-
gdTrueColor(
3048+
gdTrueColorAlpha(
30493049
(int) ((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255) + .5),
30503050
(int) ((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255) + .5),
3051-
(int) ((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255) + .5)
3051+
(int) ((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255) + .5),
3052+
gdTrueColorGetAlpha(c)
30523053
)
30533054
);
30543055
}

ext/gd/tests/bug61221.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #61221 - imagegammacorrect function loses alpha channel
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$imagew = 50;
10+
$imageh = 50;
11+
$img = imagecreatetruecolor($imagew, $imageh);
12+
$blacktransparent = imagecolorallocatealpha($img, 0, 0, 0, 127);
13+
$redsolid = imagecolorallocate($img, 255, 0, 0);
14+
imagefill($img, 0, 0, $blacktransparent);
15+
imageline($img, $imagew / 2, 0, $imagew / 2, $imageh - 1, $redsolid);
16+
imageline($img, 0, $imageh / 2, $imagew - 1, $imageh / 2, $redsolid);
17+
imagegammacorrect($img, 1, 1);
18+
$color = imagecolorat($img, 0, 0);
19+
var_dump($color === $blacktransparent);
20+
imagedestroy($img);
21+
?>
22+
--EXPECT--
23+
bool(true)

0 commit comments

Comments
 (0)