Skip to content

Commit cd94cf6

Browse files
committed
Fix #77943: imageantialias($image, false); does not work
Firstly, we must not call `gdImageSetAntiAliased()` (which sets the color to anti-alias), but rather modify the `gdImage.AA` flag. Furthermore, we have to actually use the supplied boolean value. We also make sure that we don't attempt to enable anti-aliasing for palette images.
1 parent 9bf1104 commit cd94cf6

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- FPM:
66
. Fixed bug #77921 (static.php.net doesn't work anymore). (Peter Kokot)
77

8+
- GD:
9+
. Fixed bug #77943 (imageantialias($image, false); does not work). (cmb)
10+
811
- JSON:
912
. Fixed bug #77843 (Use after free with json serializer). (Nikita)
1013

ext/gd/gd.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4699,7 +4699,11 @@ PHP_FUNCTION(imageantialias)
46994699
if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) {
47004700
RETURN_FALSE;
47014701
}
4702-
gdImageSetAntiAliased(im, 0);
4702+
4703+
if (im->trueColor) {
4704+
im->AA = alias;
4705+
}
4706+
47034707
RETURN_TRUE;
47044708
}
47054709
/* }}} */

ext/gd/tests/bug77943.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #77943 (imageantialias($image, false); does not work)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . '/func.inc';
10+
11+
$width = 400;
12+
$height = 300;
13+
$im = imagecreatetruecolor($width, $height);
14+
$white = imagecolorallocate($im, 255, 255, 255);
15+
$blue = imagecolorallocate($im, 0, 0, 255);
16+
17+
imageantialias($im, false);
18+
imagefilledrectangle($im, 0, 0, $width-1, $height-1, $white);
19+
20+
imageline($im, 0, 0, $width, $height, $blue);
21+
imagesetthickness($im, 3);
22+
imageline($im, 10, 0, $width, $height-10, $blue);
23+
24+
test_image_equals_file(__DIR__ . '/bug77943.png', $im);
25+
?>
26+
===DONE===
27+
--EXPECT--
28+
The images are equal.
29+
===DONE===

ext/gd/tests/bug77943.png

2.14 KB
Loading

0 commit comments

Comments
 (0)