imagefilledpolygon_basic.phpt 2.0 KB

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