xref: /PHP-7.4/ext/gd/tests/bug77198_auto.phpt (revision 209e37db)
1--TEST--
2Bug #77198 (auto cropping has insufficient precision)
3--SKIPIF--
4<?php
5if (!extension_loaded('gd')) die('skip gd extension not available');
6if (!GD_BUNDLED) die('skip upstream bugfix has not been released');
7?>
8--FILE--
9<?php
10
11function createWhiteImageWithBlackPixelAt($x, $y)
12{
13    $im = imagecreatetruecolor(8, 8);
14    imagefilledrectangle($im, 0, 0, 7, 7, 0xffffff);
15    imagesetpixel($im, $x, $y, 0x000000);
16    return $im;
17}
18
19for ($y = 0; $y < 8; $y++) {
20    for ($x = 0; $x < 8; $x++) {
21        if (($x == 0 && ($y == 0 || $y == 7)) || ($x == 7 && ($y == 0 || $y == 7))) {
22            continue; // skip the corners
23        }
24        $orig = createWhiteImageWithBlackPixelAt($x, $y);
25        $cropped = imagecropauto($orig, IMG_CROP_SIDES);
26        if (!$cropped) {
27            printf("Pixel at %d, %d: unexpected NULL crop\n", $x, $y);
28        } else {
29            $width = imagesx($cropped);
30            if ($width !== 1) {
31                printf("Pixel at %d, %d: unexpected width (%d)\n", $x, $y, $width);
32            }
33            $height = imagesy($cropped);
34            if ($height !== 1) {
35                printf("Pixel at %d, %d: unexpected height (%d)\n", $x, $y, $height);
36            }
37            $color = imagecolorat($cropped, 0, 0);
38            if ($color !== 0x000000) {
39                printf("Pixel at %d, %d: unexpected color (%d)\n", $x, $y, $color);
40            }
41            imagedestroy($cropped);
42        }
43        imagedestroy($orig);
44    }
45}
46
47?>
48===DONE===
49--EXPECT--
50===DONE===
51