xref: /PHP-7.1/ext/gd/tests/bug53156.phpt (revision 7af945e2)
1--TEST--
2Bug #53156 (imagerectangle problem with point ordering)
3--SKIPIF--
4<?php
5if (!extension_loaded('gd')) die('skip gd extension not available');
6if (!GD_BUNDLED && version_compare(GD_VERSION, '2.3', '<')) {
7    die("skip test requires GD 2.3 or newer");
8}
9?>
10--FILE--
11<?php
12function draw_and_check_pixel($x, $y)
13{
14    global $img, $black, $red;
15
16    echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';
17    imagesetpixel($img, $x, $y, $red);
18}
19
20function draw_and_check_rectangle($x1, $y1, $x2, $y2)
21{
22    global $img, $black;
23
24    echo 'Rectangle: ';
25    imagerectangle($img, $x1, $y1, $x2, $y2, $black);
26    $x = ($x1 + $x2) / 2;
27    $y = ($y1 + $y2) / 2;
28    draw_and_check_pixel($x,  $y1);
29    draw_and_check_pixel($x1, $y);
30    draw_and_check_pixel($x,  $y2);
31    draw_and_check_pixel($x2, $y);
32    echo PHP_EOL;
33}
34
35$img = imagecreate(110, 210);
36$bgnd  = imagecolorallocate($img, 255, 255, 255);
37$black = imagecolorallocate($img,   0,   0,   0);
38$red   = imagecolorallocate($img, 255,   0,   0);
39
40draw_and_check_rectangle( 10,  10,  50,  50);
41draw_and_check_rectangle( 50,  60,  10, 100);
42draw_and_check_rectangle( 50, 150,  10, 110);
43draw_and_check_rectangle( 10, 200,  50, 160);
44imagesetthickness($img, 4);
45draw_and_check_rectangle( 60,  10, 100,  50);
46draw_and_check_rectangle(100,  60,  60, 100);
47draw_and_check_rectangle(100, 150,  60, 110);
48draw_and_check_rectangle( 60, 200, 100, 160);
49
50//imagepng($img, __DIR__ . '/bug53156.png'); // debug
51?>
52--EXPECT--
53Rectangle: ++++
54Rectangle: ++++
55Rectangle: ++++
56Rectangle: ++++
57Rectangle: ++++
58Rectangle: ++++
59Rectangle: ++++
60Rectangle: ++++
61