imagepolygon_basic.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. imagepolygon()
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!function_exists('imagepolygon')) die('skip imagepolygon() not available');
  8. ?>
  9. --FILE--
  10. <?php
  11. echo "Simple test of imagepolygon() function\n";
  12. $dest = dirname(realpath(__FILE__)) . '/imagepolygon.png';
  13. // create a blank image
  14. $image = imagecreatetruecolor(400, 300);
  15. // set the background color to black
  16. $bg = imagecolorallocate($image, 0, 0, 0);
  17. // draw a red polygon
  18. $col_poly = imagecolorallocate($image, 255, 0, 0);
  19. // draw the polygon
  20. imagepolygon($image, array (
  21. 0, 0,
  22. 100, 200,
  23. 300, 200
  24. ),
  25. $col_poly);
  26. // output the picture to a file
  27. imagepng($image, $dest);
  28. $col1 = imagecolorat($image, 100, 200);
  29. $col2 = imagecolorat($image, 100, 100);
  30. $color1 = imagecolorsforindex($image, $col1);
  31. $color2 = imagecolorsforindex($image, $col2);
  32. var_dump($color1, $color2);
  33. imagedestroy($image);
  34. echo "Done\n";
  35. ?>
  36. --CLEAN--
  37. <?php
  38. $dest = dirname(realpath(__FILE__)) . '/imagepolygon.png';
  39. @unlink($dest);
  40. ?>
  41. --EXPECT--
  42. Simple test of imagepolygon() function
  43. array(4) {
  44. ["red"]=>
  45. int(255)
  46. ["green"]=>
  47. int(0)
  48. ["blue"]=>
  49. int(0)
  50. ["alpha"]=>
  51. int(0)
  52. }
  53. array(4) {
  54. ["red"]=>
  55. int(0)
  56. ["green"]=>
  57. int(0)
  58. ["blue"]=>
  59. int(0)
  60. ["alpha"]=>
  61. int(0)
  62. }
  63. Done