bug47946.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Bug #47946 (ImageConvolution overwrites background)
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstream fix not yet released');
  8. ?>
  9. --FILE--
  10. <?php
  11. function array_flatten($array)
  12. {
  13. $tempArray = array();
  14. foreach ($array as $value) {
  15. if (is_array($value)) {
  16. $tempArray = array_merge($tempArray, array_flatten($value));
  17. } else {
  18. $tempArray[] = $value;
  19. }
  20. }
  21. return $tempArray;
  22. }
  23. function makeFilter($resource, $matrix, $offset = 1.0)
  24. {
  25. $divisor = array_sum(array_flatten($matrix));
  26. if ($divisor == 0) {
  27. $divisor = .01;
  28. }
  29. return imageconvolution($resource, $matrix, $divisor, $offset);
  30. }
  31. $edgeMatrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
  32. $im = imagecreatetruecolor(40, 40);
  33. imagealphablending($im, false);
  34. imagefilledrectangle($im, 0, 0, 39, 39, 0x7fffffff);
  35. imagefilledellipse($im, 19, 19, 20, 20, 0x00ff00);
  36. imagesavealpha($im, true);
  37. makeFilter($im, $edgeMatrix);
  38. require_once __DIR__ . '/func.inc';
  39. test_image_equals_file(__DIR__ . '/bug47946_exp.png', $im);
  40. ?>
  41. --EXPECT--
  42. The images are equal.