bug77198_threshold.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Bug #77198 (threshold 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. $orig = createWhiteImageWithBlackPixelAt($x, $y);
  21. $cropped = imagecropauto($orig, IMG_CROP_THRESHOLD, 1, 0xffffff);
  22. if (!$cropped) {
  23. printf("Pixel at %d, %d: unexpected NULL crop\n", $x, $y);
  24. } else {
  25. $width = imagesx($cropped);
  26. if ($width !== 1) {
  27. printf("Pixel at %d, %d: unexpected width (%d)\n", $x, $y, $width);
  28. }
  29. $height = imagesy($cropped);
  30. if ($height !== 1) {
  31. printf("Pixel at %d, %d: unexpected height (%d)\n", $x, $y, $height);
  32. }
  33. $color = imagecolorat($cropped, 0, 0);
  34. if ($color !== 0x000000) {
  35. printf("Pixel at %d, %d: unexpected color (%d)\n", $x, $y, $color);
  36. }
  37. imagedestroy($cropped);
  38. }
  39. imagedestroy($orig);
  40. }
  41. }
  42. ?>
  43. ===DONE===
  44. --EXPECT--
  45. ===DONE===