xref: /PHP-8.1/ext/gd/tests/libgd00100.phpt (revision b6958bb8)
1--TEST--
2libgd #100 (spurious horizontal line drawn by gdImageFilledPolygon)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!GD_BUNDLED) die("skip requires bundled GD library\n");
8?>
9--FILE--
10<?php
11$im = imagecreatetruecolor(256, 256);
12
13$white   = imagecolorallocatealpha($im, 255, 255, 255, 10);
14$black   = imagecolorallocatealpha($im,   0,   0,   0, 10);
15$red     = imagecolorallocatealpha($im, 255,   0,   0, 10);
16$green   = imagecolorallocatealpha($im,   0, 255,   0, 10);
17$blue    = imagecolorallocatealpha($im,   0,   0, 255, 10);
18$yellow  = imagecolorallocatealpha($im, 255, 255,   0, 10);
19$cyan    = imagecolorallocatealpha($im,   0, 255, 255, 10);
20$magenta = imagecolorallocatealpha($im, 255,   0, 255, 10);
21$purple  = imagecolorallocatealpha($im, 100,   0, 100, 10);
22
23imagefilledrectangle($im, 0, 0, 255, 255, $white);
24
25// M (bridge)
26$top = 240;
27$bot = 255;
28$d = 30;
29$x = 100;
30$points = array(
31  $x,      $top,
32  $x+2*$d, $top,
33  $x+2*$d, $bot,
34  $x+$d,   (int) (($top+$bot)/2),
35  $x,      $bot
36);
37imagefilledpolygon($im, $points, $yellow);
38
39// left-facing M not on baseline
40$top = 40;
41$bot = 70;
42$left = 120;
43$right = 180;
44$points = array(
45  $left,  $top,
46  $right, $top,
47  $right, $bot,
48  $left,  $bot,
49  ($left+$right)/2, ($top+$bot)/2
50);
51imagefilledpolygon($im, $points, $purple);
52
53// left-facing M on baseline
54$top = 240;
55$bot = 270;
56$left = 20;
57$right = 80;
58$points = array(
59  $left,  $top,
60  $right, $top,
61  $right, $bot,
62  $left,  $bot,
63  ($left+$right)/2, ($top+$bot)/2
64);
65imagefilledpolygon($im, $points, $magenta);
66
67// left-facing M on ceiling
68$top = -15;
69$bot = 15;
70$left = 20;
71$right = 80;
72$points = array(
73  $left,  $top,
74  $right, $top,
75  $right, $bot,
76  $left,  $bot,
77  ($left+$right)/2, ($top+$bot)/2
78);
79imagefilledpolygon($im, $points, $blue);
80
81$d = 30;
82$x = 150;
83$y = 150;
84$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
85imagefilledpolygon($im, $diamond, $green);
86
87$x = 180;
88$y = 225;
89$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
90imagefilledpolygon($im, $diamond, $red);
91
92$x = 225;
93$y = 255;
94$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
95imagefilledpolygon($im, $diamond, $cyan);
96
97// M (bridge) not touching bottom boundary
98$top = 100;
99$bot = 150;
100$x = 30;
101$points = array(
102  $x,      $top,
103  $x+2*$d, $top,
104  $x+2*$d, $bot,
105  $x+$d,   ($top+$bot)/2,
106  $x,      $bot
107);
108imagefilledpolygon($im, $points, $black);
109
110include_once __DIR__ . '/func.inc';
111test_image_equals_file(__DIR__ . '/libgd00100.png', $im);
112
113imagedestroy($im);
114?>
115--EXPECT--
116The images are equal.
117