xref: /PHP-7.1/ext/gd/tests/createfromstring.phpt (revision 0a92fdba)
1--TEST--
2imagecreatefromstring
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);
13imagefill($im, 0,0, 0xffffff);
14imagesetpixel($im, 3,3, 0x0);
15imagepng($im, $dir . '/tc.png');
16
17$im_string = file_get_contents(dirname(__FILE__) . '/tc.png');
18$im = imagecreatefromstring($im_string);
19echo 'createfromstring truecolor png: ';
20if (imagecolorat($im, 3,3) != 0x0) {
21	echo 'failed';
22} else {
23	echo 'ok';
24}
25echo "\n";
26unlink($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);
33imagefill($im, 0,0, $c1);
34imagesetpixel($im, 3,3, $c2);
35imagepng($im, $dir . '/p.png');
36
37$im_string = file_get_contents(dirname(__FILE__) . '/p.png');
38$im = imagecreatefromstring($im_string);
39
40echo'createfromstring palette png: ';
41
42$c = imagecolorsforindex($im, imagecolorat($im, 3,3));
43$failed = false;
44if ($c['red'] != 255 || $c['green'] != 0 || $c['blue'] != 0) {
45	echo 'failed';
46} else {
47	echo 'ok';
48}
49echo "\n";
50unlink($dir . '/p.png');
51
52
53//empty string
54$im = imagecreatefromstring('');
55//random string > 8
56$im = imagecreatefromstring(' asdf jklp');
57?>
58--EXPECTF--
59createfromstring truecolor png: ok
60createfromstring palette png: ok
61
62Warning: imagecreatefromstring(): Empty string or invalid image in %screatefromstring.php on line %d
63
64Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d
65