1--TEST--
2Bug #77198 (threshold 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        $orig = createWhiteImageWithBlackPixelAt($x, $y);
22        $cropped = imagecropauto($orig, IMG_CROP_THRESHOLD, 1, 0xffffff);
23        if (!$cropped) {
24            printf("Pixel at %d, %d: unexpected NULL crop\n", $x, $y);
25        } else {
26            $width = imagesx($cropped);
27            if ($width !== 1) {
28                printf("Pixel at %d, %d: unexpected width (%d)\n", $x, $y, $width);
29            }
30            $height = imagesy($cropped);
31            if ($height !== 1) {
32                printf("Pixel at %d, %d: unexpected height (%d)\n", $x, $y, $height);
33            }
34            $color = imagecolorat($cropped, 0, 0);
35            if ($color !== 0x000000) {
36                printf("Pixel at %d, %d: unexpected color (%d)\n", $x, $y, $color);
37            }
38            imagedestroy($cropped);
39        }
40        imagedestroy($orig);
41    }
42}
43
44?>
45===DONE===
46--EXPECT--
47===DONE===
48