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