xref: /PHP-8.2/ext/gd/tests/bug75124.phpt (revision a375d547)
1--TEST--
2Bug #75124 (gdImageGrayScale() may produce colors)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<')) {
8    die('skip only for bundled libgd or external libgd >= 2.2.5');
9}
10?>
11--FILE--
12<?php
13$im = imagecreatefrompng(__DIR__ . '/bug75124.png');
14var_dump(imageistruecolor($im));
15imagefilter($im, IMG_FILTER_GRAYSCALE);
16for ($i = 0, $width = imagesx($im); $i < $width; $i ++) {
17    for ($j = 0, $height = imagesy($im); $j < $height; $j++) {
18        $color = imagecolorat($im, $i, $j);
19        $red = ($color >> 16) & 0xff;
20        $green = ($color >> 8) & 0xff;
21        $blue = $color & 0xff;
22        if ($red != $green || $green != $blue) {
23            echo "non grayscale pixel detected\n";
24            break 2;
25        }
26    }
27}
28?>
29--EXPECT--
30bool(true)
31