Annotation of embedaddon/php/ext/gd/tests/createfromstring.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: imagecreatefromstring
3: --SKIPIF--
4: <?php
5: if (!function_exists('imagecreatefromstring')) die("skip gd extension not available\n");
6: if (!function_exists('imagepng')) die("skip no imagpng()\n");
7: ?>
8: --FILE--
9: <?php
10: $dir = dirname(__FILE__);
11:
12: $im = imagecreatetruecolor(5,5);
13: imagefill($im, 0,0, 0xffffff);
14: imagesetpixel($im, 3,3, 0x0);
15: imagepng($im, $dir . '/tc.png');
16:
17: $im_string = file_get_contents(dirname(__FILE__) . '/tc.png');
18: $im = imagecreatefromstring($im_string);
19: echo 'createfromstring truecolor png: ';
20: if (imagecolorat($im, 3,3) != 0x0) {
21: echo 'failed';
22: } else {
23: echo 'ok';
24: }
25: echo "\n";
26: unlink($dir . '/tc.png');
27:
28:
29:
30: $im = imagecreate(5,5);
31: $c1 = imagecolorallocate($im, 255,255,255);
32: $c2 = imagecolorallocate($im, 255,0,0);
33: imagefill($im, 0,0, $c1);
34: imagesetpixel($im, 3,3, $c2);
35: imagepng($im, $dir . '/p.png');
36:
37: $im_string = file_get_contents(dirname(__FILE__) . '/p.png');
38: $im = imagecreatefromstring($im_string);
39:
40: echo'createfromstring palette png: ';
41:
42: $c = imagecolorsforindex($im, imagecolorat($im, 3,3));
43: $failed = false;
44: if ($c['red'] != 255 || $c['green'] != 0 || $c['blue'] != 0) {
45: echo 'failed';
46: } else {
47: echo 'ok';
48: }
49: echo "\n";
50: unlink($dir . '/p.png');
51:
52:
53: //empty string
54: $im = imagecreatefromstring('');
55: //random string > 8
56: $im = imagecreatefromstring(' asdf jklp');
57: ?>
58: --EXPECTF--
59: createfromstring truecolor png: ok
60: createfromstring palette png: ok
61:
62: Warning: imagecreatefromstring(): Empty string or invalid image in %screatefromstring.php on line %d
63:
64: Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>