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