Search code examples
imageimagemagickimagemagick-convert

With ImageMagick, why do I get a halo when flattening a PSD with alpha?


I have a large number of PSD files which contain semi-transparent layers. These layers are not getting flattened correctly regardless of what flags I use via convert or mogrify

The simplest form looks as follows:

convert -background transparent source.psd -flatten  output.png

Here is what the source image looks like in Photoshop. Note that this is a drop shadow layer and not a layer effect:

enter image description here

Here is how it comes out:

enter image description here

This may not be obvious from the photoshop background, so here it is in laid over a grey background:

Source:

enter image description here

Output:

enter image description here

EDIT: I dug a bit into what is happening in the numbers. For the initial source image, the shadow is completely black and the alpha fades in. For the output image, the alpha is not as high, but it compensates by inaccurately lightening the image in a somewhat bumpy fashion. Its almost as if its pre-multiplied, but its taking the background as white?

Here is a strait RGB render without alpha multiplied in:

Source:

enter image description here

Output:

enter image description here

In other words, the RBG values are not at all being preserved. Alpha is being dimmed, but not distorted as theses values are. My guess would be some sort of rounding error based on trying to extrapolate the color from the alpha as though it is trying to "unpre-multiply" the values. Any help is appreciated.


Solution

  • Short answer is it is fixed in V7 of the software (I think). I run mac and the installer for V7 doesn't work well at all and it appears unstable. After running it on an Ubuntu VM, it works good. I have also confirmed with another user that V6 has this problem and V7 does not on Windows