xref: /PHP-8.4/ext/gd/tests/lines.phpt (revision a375d547)
1--TEST--
2imageline no AA
3--EXTENSIONS--
4gd
5--FILE--
6<?php
7$im = imagecreatetruecolor(6,6);
8imagefill($im, 0,0, 0xffffff);
9
10// Horizontal line
11imageline($im, 0,5, 5,5, 0x00ff00);
12
13$p1 = imagecolorat($im, 0,5)==0x00ff00;
14$p2 = imagecolorat($im, 5,5)==0x00ff00;
15$p3 = true;
16for ($x=1; $x<5; $x++) {
17    $p3 = $p3 && (imagecolorat($im, $x,5)==0x00ff00);
18}
19if ($p1 && $p2 && $p3) {
20    echo "Horizontal: ok\n";
21}
22
23$im = imagecreatetruecolor(6,6);
24imagefill($im, 0,0, 0xffffff);
25
26imageline($im, 0,0, 0,5, 0x00ff00);
27$p1 = imagecolorat($im, 0,0)==0x00ff00;
28$p2 = imagecolorat($im, 0,5)==0x00ff00;
29$p3 = true;
30for ($y=1; $y<5; $y++) {
31    $p3 = $p3 && (imagecolorat($im, 0,$y)==0x00ff00);
32}
33
34if ($p1 && $p2 && $p3) {
35    echo "Vertical: ok\n";
36}
37
38
39$im = imagecreatetruecolor(6,6);
40imagefill($im, 0,0, 0xffffff);
41imageline($im, 0,0, 5,5, 0x00ff00);
42
43
44// Diagonal
45$p1 = imagecolorat($im, 0,0)==0x00ff00;
46$p2 = imagecolorat($im, 5,5)==0x00ff00;
47$x=1;
48$p3 = true;
49
50for ($y=1; $y<5; $y++) {
51    $p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
52    $x++;
53}
54
55if ($p1 && $p2 && $p3) {
56    echo "Diagonal: ok\n";
57}
58
59// Outside
60$im = imagecreatetruecolor(6,6);
61imagefill($im, 0,0, 0xffffff);
62imageline($im, 12, 12, 23,23, 0x00ff00);
63$p3 = true;
64for ($x=0; $x<6; $x++) {
65    for ($y=0; $y<6; $y++) {
66        $p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
67    }
68}
69if ($p3) {
70    echo "Outside 1: ok\n";
71}
72
73$im = imagecreatetruecolor(6,6);
74imagefill($im, 0,0, 0xffffff);
75imageline($im, -12, -12, -23,-23, 0x00ff00);
76$p3 = true;
77for ($x=0; $x<6; $x++) {
78    for ($y=0; $y<6; $y++) {
79        $p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
80    }
81}
82if ($p3) {
83    echo "Outside 2: ok\n";
84}
85
86$im = imagecreatetruecolor(6,6);
87imagefill($im, 0,0, 0xffffff);
88imageline($im, -1, -1, 4,4, 0x00ff00);
89$p3 = true;
90for ($x=0; $x<5; $x++) {
91    for ($y=0; $y<5; $y++) {
92        $p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
93    }
94}
95if ($p3) {
96    echo "Outside 2: ok\n";
97}
98
99
100?>
101--EXPECT--
102Horizontal: ok
103Vertical: ok
104Diagonal: ok
105Outside 1: ok
106Outside 2: ok
107