bug53156.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Bug #53156 (imagerectangle problem with point ordering)
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!GD_BUNDLED && version_compare(GD_VERSION, '2.3', '<')) {
  8. die("skip test requires GD 2.3 or newer");
  9. }
  10. ?>
  11. --FILE--
  12. <?php
  13. function draw_and_check_pixel($x, $y)
  14. {
  15. global $img, $black, $red;
  16. echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';
  17. imagesetpixel($img, $x, $y, $red);
  18. }
  19. function draw_and_check_rectangle($x1, $y1, $x2, $y2)
  20. {
  21. global $img, $black;
  22. echo 'Rectangle: ';
  23. imagerectangle($img, $x1, $y1, $x2, $y2, $black);
  24. $x = ($x1 + $x2) / 2;
  25. $y = ($y1 + $y2) / 2;
  26. draw_and_check_pixel($x, $y1);
  27. draw_and_check_pixel($x1, $y);
  28. draw_and_check_pixel($x, $y2);
  29. draw_and_check_pixel($x2, $y);
  30. echo PHP_EOL;
  31. }
  32. $img = imagecreate(110, 210);
  33. $bgnd = imagecolorallocate($img, 255, 255, 255);
  34. $black = imagecolorallocate($img, 0, 0, 0);
  35. $red = imagecolorallocate($img, 255, 0, 0);
  36. draw_and_check_rectangle( 10, 10, 50, 50);
  37. draw_and_check_rectangle( 50, 60, 10, 100);
  38. draw_and_check_rectangle( 50, 150, 10, 110);
  39. draw_and_check_rectangle( 10, 200, 50, 160);
  40. imagesetthickness($img, 4);
  41. draw_and_check_rectangle( 60, 10, 100, 50);
  42. draw_and_check_rectangle(100, 60, 60, 100);
  43. draw_and_check_rectangle(100, 150, 60, 110);
  44. draw_and_check_rectangle( 60, 200, 100, 160);
  45. //imagepng($img, __DIR__ . '/bug53156.png'); // debug
  46. ?>
  47. --EXPECT--
  48. Rectangle: ++++
  49. Rectangle: ++++
  50. Rectangle: ++++
  51. Rectangle: ++++
  52. Rectangle: ++++
  53. Rectangle: ++++
  54. Rectangle: ++++
  55. Rectangle: ++++