|
| 1 | +--TEST-- |
| 2 | +Bug #53156 (imagerectangle problem with point ordering) |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded('gd')) die('skip gd extension not available'); |
| 6 | +?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +function draw_and_check_pixel($x, $y) |
| 10 | +{ |
| 11 | + global $img, $black, $red; |
| 12 | + |
| 13 | + echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-'; |
| 14 | + imagesetpixel($img, $x, $y, $red); |
| 15 | +} |
| 16 | + |
| 17 | +function draw_and_check_rectangle($x1, $y1, $x2, $y2) |
| 18 | +{ |
| 19 | + global $img, $black; |
| 20 | + |
| 21 | + echo 'Rectangle: '; |
| 22 | + imagerectangle($img, $x1, $y1, $x2, $y2, $black); |
| 23 | + $x = ($x1 + $x2) / 2; |
| 24 | + $y = ($y1 + $y2) / 2; |
| 25 | + draw_and_check_pixel($x, $y1); |
| 26 | + draw_and_check_pixel($x1, $y); |
| 27 | + draw_and_check_pixel($x, $y2); |
| 28 | + draw_and_check_pixel($x2, $y); |
| 29 | + echo PHP_EOL; |
| 30 | +} |
| 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 | + |
| 37 | +draw_and_check_rectangle( 10, 10, 50, 50); |
| 38 | +draw_and_check_rectangle( 50, 60, 10, 100); |
| 39 | +draw_and_check_rectangle( 50, 150, 10, 110); |
| 40 | +draw_and_check_rectangle( 10, 200, 50, 160); |
| 41 | +imagesetthickness($img, 4); |
| 42 | +draw_and_check_rectangle( 60, 10, 100, 50); |
| 43 | +draw_and_check_rectangle(100, 60, 60, 100); |
| 44 | +draw_and_check_rectangle(100, 150, 60, 110); |
| 45 | +draw_and_check_rectangle( 60, 200, 100, 160); |
| 46 | + |
| 47 | +//imagepng($img, __DIR__ . '/bug53156.png'); // debug |
| 48 | +?> |
| 49 | +--EXPECT-- |
| 50 | +Rectangle: ++++ |
| 51 | +Rectangle: ++++ |
| 52 | +Rectangle: ++++ |
| 53 | +Rectangle: ++++ |
| 54 | +Rectangle: ++++ |
| 55 | +Rectangle: ++++ |
| 56 | +Rectangle: ++++ |
| 57 | +Rectangle: ++++ |
0 commit comments