createfromstring.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $im = imagecreatetruecolor(5,5);
  12. imagefill($im, 0,0, 0xffffff);
  13. imagesetpixel($im, 3,3, 0x0);
  14. imagepng($im, $dir . '/tc.png');
  15. $im_string = file_get_contents(dirname(__FILE__) . '/tc.png');
  16. $im = imagecreatefromstring($im_string);
  17. echo 'createfromstring truecolor png: ';
  18. if (imagecolorat($im, 3,3) != 0x0) {
  19. echo 'failed';
  20. } else {
  21. echo 'ok';
  22. }
  23. echo "\n";
  24. unlink($dir . '/tc.png');
  25. $im = imagecreate(5,5);
  26. $c1 = imagecolorallocate($im, 255,255,255);
  27. $c2 = imagecolorallocate($im, 255,0,0);
  28. imagefill($im, 0,0, $c1);
  29. imagesetpixel($im, 3,3, $c2);
  30. imagepng($im, $dir . '/p.png');
  31. $im_string = file_get_contents(dirname(__FILE__) . '/p.png');
  32. $im = imagecreatefromstring($im_string);
  33. echo'createfromstring palette png: ';
  34. $c = imagecolorsforindex($im, imagecolorat($im, 3,3));
  35. $failed = false;
  36. if ($c['red'] != 255 || $c['green'] != 0 || $c['blue'] != 0) {
  37. echo 'failed';
  38. } else {
  39. echo 'ok';
  40. }
  41. echo "\n";
  42. unlink($dir . '/p.png');
  43. //empty string
  44. $im = imagecreatefromstring('');
  45. //random string > 12
  46. $im = imagecreatefromstring(' asdf jklp foo');
  47. ?>
  48. --EXPECTF--
  49. createfromstring truecolor png: ok
  50. createfromstring palette png: ok
  51. Warning: imagecreatefromstring(): Empty string or invalid image in %screatefromstring.php on line %d
  52. Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d