bug77198_auto.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Bug #77198 (auto cropping has insufficient precision)
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!GD_BUNDLED) die('skip upstream bugfix has not been released');
  8. ?>
  9. --FILE--
  10. <?php
  11. function createWhiteImageWithBlackPixelAt($x, $y)
  12. {
  13. $im = imagecreatetruecolor(8, 8);
  14. imagefilledrectangle($im, 0, 0, 7, 7, 0xffffff);
  15. imagesetpixel($im, $x, $y, 0x000000);
  16. return $im;
  17. }
  18. for ($y = 0; $y < 8; $y++) {
  19. for ($x = 0; $x < 8; $x++) {
  20. if (($x == 0 && ($y == 0 || $y == 7)) || ($x == 7 && ($y == 0 || $y == 7))) {
  21. continue; // skip the corners
  22. }
  23. $orig = createWhiteImageWithBlackPixelAt($x, $y);
  24. $cropped = imagecropauto($orig, IMG_CROP_SIDES);
  25. if (!$cropped) {
  26. printf("Pixel at %d, %d: unexpected NULL crop\n", $x, $y);
  27. } else {
  28. $width = imagesx($cropped);
  29. if ($width !== 1) {
  30. printf("Pixel at %d, %d: unexpected width (%d)\n", $x, $y, $width);
  31. }
  32. $height = imagesy($cropped);
  33. if ($height !== 1) {
  34. printf("Pixel at %d, %d: unexpected height (%d)\n", $x, $y, $height);
  35. }
  36. $color = imagecolorat($cropped, 0, 0);
  37. if ($color !== 0x000000) {
  38. printf("Pixel at %d, %d: unexpected color (%d)\n", $x, $y, $color);
  39. }
  40. imagedestroy($cropped);
  41. }
  42. imagedestroy($orig);
  43. }
  44. }
  45. ?>
  46. ===DONE===
  47. --EXPECT--
  48. ===DONE===