imagefilledpolygon_basic.phpt 2.1 KB

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