xref: /PHP-5.4/ext/gd/tests/lines.phpt (revision 1c7f474e)
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// Wrong argument count
13imageline($im, 0,0, 5,5);
14
15
16// Horizontal line
17imageline($im, 0,5, 5,5, 0x00ff00);
18
19$p1 = imagecolorat($im, 0,5)==0x00ff00;
20$p2 = imagecolorat($im, 5,5)==0x00ff00;
21$p3 = true;
22for ($x=1; $x<5; $x++) {
23	$p3 = $p3 && (imagecolorat($im, $x,5)==0x00ff00);
24}
25if ($p1 && $p2 && $p3) {
26	echo "Horizontal: ok\n";
27}
28
29$im = imagecreatetruecolor(6,6);
30imagefill($im, 0,0, 0xffffff);
31
32imageline($im, 0,0, 0,5, 0x00ff00);
33$p1 = imagecolorat($im, 0,0)==0x00ff00;
34$p2 = imagecolorat($im, 0,5)==0x00ff00;
35$p3 = true;
36for ($y=1; $y<5; $y++) {
37	$p3 = $p3 && (imagecolorat($im, 0,$y)==0x00ff00);
38}
39
40if ($p1 && $p2 && $p3) {
41	echo "Vertical: ok\n";
42}
43
44
45$im = imagecreatetruecolor(6,6);
46imagefill($im, 0,0, 0xffffff);
47imageline($im, 0,0, 5,5, 0x00ff00);
48
49
50// Diagonal
51$p1 = imagecolorat($im, 0,0)==0x00ff00;
52$p2 = imagecolorat($im, 5,5)==0x00ff00;
53$x=1;
54$p3 = true;
55
56for ($y=1; $y<5; $y++) {
57	$p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
58	$x++;
59}
60
61if ($p1 && $p2 && $p3) {
62	echo "Diagonal: ok\n";
63}
64
65// Outside
66$im = imagecreatetruecolor(6,6);
67imagefill($im, 0,0, 0xffffff);
68imageline($im, 12, 12, 23,23, 0x00ff00);
69$p3 = true;
70for ($x=0; $x<6; $x++) {
71	for ($y=0; $y<6; $y++) {
72		$p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
73	}
74}
75if ($p3) {
76	echo "Outside 1: ok\n";
77}
78
79$im = imagecreatetruecolor(6,6);
80imagefill($im, 0,0, 0xffffff);
81imageline($im, -12, -12, -23,-23, 0x00ff00);
82$p3 = true;
83for ($x=0; $x<6; $x++) {
84	for ($y=0; $y<6; $y++) {
85		$p3 = $p3 && (imagecolorat($im, $x,$y)!=0x00ff00);
86	}
87}
88if ($p3) {
89	echo "Outside 2: ok\n";
90}
91
92$im = imagecreatetruecolor(6,6);
93imagefill($im, 0,0, 0xffffff);
94imageline($im, -1, -1, 4,4, 0x00ff00);
95$p3 = true;
96for ($x=0; $x<5; $x++) {
97	for ($y=0; $y<5; $y++) {
98		$p3 = $p3 && (imagecolorat($im, $x,$y)==0x00ff00);
99	}
100}
101if ($p3) {
102	echo "Outside 2: ok\n";
103}
104
105
106?>
107--EXPECTF--
108
109Warning: imageline() expects exactly 6 parameters, 5 given in %s on line %d
110Horizontal: ok
111Vertical: ok
112Diagonal: ok
113Outside 1: ok
114Outside 2: ok
115