imagepolygon_basic.phpt 1.5 KB

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