imagefilledpolygon_basic.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. --TEST--
  2. imagefilledpolygon()
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!function_exists('imagefilledpolygon')) die('skip imagefilledpolygon() not available');
  8. ?>
  9. --FILE--
  10. <?php
  11. echo "Simple test of imagefilledpolygon() function\n";
  12. $dest = dirname(realpath(__FILE__)) . '/imagefilledpolygon.png';
  13. $points = array(
  14. 40, 50,
  15. 20, 240,
  16. 60, 60,
  17. 240, 20,
  18. 50, 40,
  19. 10, 10
  20. );
  21. // create a blank image
  22. $image = imagecreatetruecolor(250, 250);
  23. // set the background color to black
  24. $bg = imagecolorallocate($image, 0, 0, 0);
  25. // fill polygon with green
  26. $col_poly = imagecolorallocate($image, 0, 255, 0);
  27. // draw the polygon
  28. imagefilledpolygon($image, $points, $col_poly);
  29. // output the picture to a file
  30. imagepng($image, $dest);
  31. // get it back
  32. $image_in = imagecreatefrompng($dest);
  33. //check color of a point on edge..
  34. $col1 = imagecolorat($image_in, 40, 50);
  35. //.. a point in filled body
  36. $col2 = imagecolorat($image_in, 15, 15);
  37. // ..and a point on background
  38. $col3 = imagecolorat($image_in, 5, 5);
  39. $color1 = imagecolorsforindex($image_in, $col1);
  40. $color2 = imagecolorsforindex($image_in, $col2);
  41. $color3 = imagecolorsforindex($image_in, $col3);
  42. var_dump($color1, $color2, $color3);
  43. imagedestroy($image);
  44. imagedestroy($image_in);
  45. echo "Done\n";
  46. ?>
  47. --CLEAN--
  48. <?php
  49. $dest = dirname(realpath(__FILE__)) . '/imagefilledpolygon.png';
  50. @unlink($dest);
  51. ?>
  52. --EXPECT--
  53. Simple test of imagefilledpolygon() function
  54. array(4) {
  55. ["red"]=>
  56. int(0)
  57. ["green"]=>
  58. int(255)
  59. ["blue"]=>
  60. int(0)
  61. ["alpha"]=>
  62. int(0)
  63. }
  64. array(4) {
  65. ["red"]=>
  66. int(0)
  67. ["green"]=>
  68. int(255)
  69. ["blue"]=>
  70. int(0)
  71. ["alpha"]=>
  72. int(0)
  73. }
  74. array(4) {
  75. ["red"]=>
  76. int(0)
  77. ["green"]=>
  78. int(0)
  79. ["blue"]=>
  80. int(0)
  81. ["alpha"]=>
  82. int(0)
  83. }
  84. Done