Alpha/Transparency No Longer Preserved Using Filters
Posted: 2013-02-07T21:26:23-07:00
Alpha is no longer being processed with the StatisticImage / filter functions in Magickwand for PHP. Was hoping an extra undocumented command had been included to do this, but from the source, doesn't appear so.
MagickMedianFilterImage and MagickReduceNoiseImage both have the problem, possibly others I haven't run across.
Had a thread over at viewtopic.php?f=3&t=22720
thinking it was a related transparency issue, but their tests suggest it's Magickwand for PHP.
The current default behavior of median filter is to drop transparency unless -alpha on or -channel rgba is applied. (works on a command line, but Magickwand for PHP fails to pass or include the alpha option).
Versions < 6.7 automatically included the alpha (or the default behavior may have been alpha on), as it works on our production system running 6.6.3. Starting at 6.7 the median filters break when alpha is used. (which one reason to use the filter is to smooth across alpha differences)
Basically, since alpha is not processed in the filter, we're left with a black overlay with sporadic solids representing the data.
Here's a quick incomplete sample involving a solid background and a foreground with alpha data.
A median filter is applied to the foreground, and the two composited. Current version mangles the alpha to opaque before processing, then covers the background in a solid black or white. Leave off the filter, or run in 6.6 and alpha behaves as expected.
$bg_in = file_get_contents("bg_opaque.jpg"); // Any solid background
$bg = NewMagickWand();
MagickReadImageBlob($bg,$bg_in);
$image_in = file_get_contents("alpha_data_image.gif"); // Any image with transparency
$data_layer = NewMagickWand();
MagickReadImageBlob($data_layer,$image_in);
MagickMedianFilterImage($data_layer,.2); // No Longer Preserves Alpha, and no option to pass alpha
MagickCompositeImage($bg,$data_layer,MW_OverCompositeOp, 0, 0);
// v6.6, nice transparent overlay, all versions after v6.6 solid blob, hard corners, and no background..
I assume it's a bug, but perhaps a method has been created to handle this that I'm missing. Our current code is broken by the 1 median filter unless it's run on v6.6.
Since it appears to be a PHP/Magickwand issue, moved the thread over here.
Thanks for any help or insight.
MagickMedianFilterImage and MagickReduceNoiseImage both have the problem, possibly others I haven't run across.
Had a thread over at viewtopic.php?f=3&t=22720
thinking it was a related transparency issue, but their tests suggest it's Magickwand for PHP.
The current default behavior of median filter is to drop transparency unless -alpha on or -channel rgba is applied. (works on a command line, but Magickwand for PHP fails to pass or include the alpha option).
Versions < 6.7 automatically included the alpha (or the default behavior may have been alpha on), as it works on our production system running 6.6.3. Starting at 6.7 the median filters break when alpha is used. (which one reason to use the filter is to smooth across alpha differences)
Basically, since alpha is not processed in the filter, we're left with a black overlay with sporadic solids representing the data.
Here's a quick incomplete sample involving a solid background and a foreground with alpha data.
A median filter is applied to the foreground, and the two composited. Current version mangles the alpha to opaque before processing, then covers the background in a solid black or white. Leave off the filter, or run in 6.6 and alpha behaves as expected.
$bg_in = file_get_contents("bg_opaque.jpg"); // Any solid background
$bg = NewMagickWand();
MagickReadImageBlob($bg,$bg_in);
$image_in = file_get_contents("alpha_data_image.gif"); // Any image with transparency
$data_layer = NewMagickWand();
MagickReadImageBlob($data_layer,$image_in);
MagickMedianFilterImage($data_layer,.2); // No Longer Preserves Alpha, and no option to pass alpha
MagickCompositeImage($bg,$data_layer,MW_OverCompositeOp, 0, 0);
// v6.6, nice transparent overlay, all versions after v6.6 solid blob, hard corners, and no background..
I assume it's a bug, but perhaps a method has been created to handle this that I'm missing. Our current code is broken by the 1 median filter unless it's run on v6.6.
Since it appears to be a PHP/Magickwand issue, moved the thread over here.
Thanks for any help or insight.