xref: /PHP-7.0/ext/gd/tests/gif.phpt (revision ace3f94d)
1--TEST--
2gif in/out
3--SKIPIF--
4<?php
5// $Id$
6	if (!extension_loaded('gd')) {
7		die("skip gd extension not available.");
8	}
9	if (!function_exists("imagegif") || !function_exists("imagecreatefromgif") || !function_exists('imagecreatefromjpeg')) {
10		die("skip gif support unavailable");
11	}
12?>
13--FILE--
14<?php
15
16function check_box($r,$g,$b, $error=0) {
17	$cwd = dirname(__FILE__);
18	$im2 = imagecreatefromgif($cwd . '/test_gif.gif');
19
20	$c = imagecolorsforindex($im2, imagecolorat($im2, 8,8));
21
22	if ($error>0) {
23		$r_min = $r - $error; $r_max = $r + $error;
24		$g_min = $g - $error; $g_max = $g + $error;
25		$b_min = $b - $error; $b_max = $b + $error;
26
27		if (
28			($c['red'] >= $r_min || $c['red'] <= $r_max)
29			&&
30			($c['green'] >= $g_min || $c['green'] <= $g_max)
31			&&
32			($c['blue'] >= $b_min || $c['blue'] <= $b_max)
33			) {
34			return true;
35		} else {
36			return false;
37		}
38	} else {
39		if ($c['red']==$r && $c['green']==$g && $c['blue']==$b) {
40			return true;
41		} else {
42			return false;
43		}
44	}
45}
46$cwd = dirname(__FILE__);
47
48$im = imagecreate(10,10);
49$c = imagecolorallocate($im, 255,255,255);
50imagefilledrectangle($im, 5,5, 10,10, $c);
51imagegif($im, $cwd . '/test_gif.gif');
52if (check_box(255,255,255)) {
53	echo "<4 cols: ok\n";
54}
55
56$im = imagecreate(10,10);
57for ($i=0; $i<7; $i++) {
58	$c = imagecolorallocate($im, $i,$i,$i);
59}
60imagefilledrectangle($im, 5,5, 10,10, $c);
61imagegif($im, $cwd . '/test_gif.gif');
62$i--;
63if (check_box($i,$i,$i)) {
64		echo "<8 cols: ok\n";
65}
66
67
68$im = imagecreate(10,10);
69for ($i=0; $i<15; $i++) {
70	$c = imagecolorallocate($im, $i,$i,$i);
71}
72imagefilledrectangle($im, 5,5, 10,10, $c);
73imagegif($im, $cwd . '/test_gif.gif');
74$i--;
75if (check_box($i,$i,$i)) {
76		echo "<16 cols: ok\n";
77}
78
79
80$im = imagecreate(10,10);
81for ($i=0; $i<31; $i++) {
82	$c = imagecolorallocate($im, $i,$i,$i);
83}
84imagefilledrectangle($im, 5,5, 10,10, $c);
85imagegif($im, $cwd . '/test_gif.gif');
86$i--;
87if (check_box($i,$i,$i)) {
88		echo "<32 cols: ok\n";
89}
90
91
92$im = imagecreate(10,10);
93for ($i=0; $i<63; $i++) {
94	$c = imagecolorallocate($im, $i,$i,$i);
95}
96imagefilledrectangle($im, 5,5, 10,10, $c);
97imagegif($im, $cwd . '/test_gif.gif');
98$i--;
99if (check_box($i,$i,$i)) {
100		echo "<64 cols: ok\n";
101}
102
103$im = imagecreate(10,10);
104for ($i=0; $i<127; $i++) {
105	$c = imagecolorallocate($im, $i,$i,$i);
106}
107imagefilledrectangle($im, 5,5, 10,10, $c);
108imagegif($im, $cwd . '/test_gif.gif');
109$i--;
110if (check_box($i,$i,$i)) {
111		echo "<128 cols: ok\n";
112}
113
114$im = imagecreate(10,10);
115for ($i=0; $i<255; $i++) {
116	$c = imagecolorallocate($im, $i,$i,$i);
117}
118imagefilledrectangle($im, 5,5, 10,10, $c);
119imagegif($im, $cwd . '/test_gif.gif');
120$i--;
121if (check_box($i,$i,$i)) {
122		echo "<256 cols: ok\n";
123}
124
125
126$im = imagecreatefromjpeg($cwd . '/conv_test.jpeg');
127imagefilledrectangle($im, 5,5, 10,10, 0xffffff);
128imagegif($im, $cwd . '/test_gif.gif');
129imagegif($im, $cwd . '/test_gif_2.gif');
130
131if (check_box(255,255,255, 10)) {
132	echo ">256 cols: ok\n";
133}
134
135@unlink($cwd . "/test_gif.gif");
136@unlink($cwd . "/test_gif_2.gif");
137?>
138--EXPECT--
139<4 cols: ok
140<8 cols: ok
141<16 cols: ok
142<32 cols: ok
143<64 cols: ok
144<128 cols: ok
145<256 cols: ok
146>256 cols: ok
147