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