Alpha not being handled correctly when flattening a gradient from a PSD file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

I have a large number of multi-layer PSD files which contain alpha gradients. The color behind these gradients are black. This is a simplified form of what I am using:

Code: Select all

convert -background transparent source.psd -flatten  output.png
When I run this conversion, the color behind the alpha gradient becomes a strange, noisy gradient (not black), and the alpha, although it stays smooth, gets dimmer. 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.

Source example over grey
Image

Converted over grey:
Image

I used AfterEffects to do a render of RGB strait, where the alpha is ignored, and the problem is even more apparent:

Source:
Image

Converted:
Image

Any help is appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by fmw42 »

try

Code: Select all

convert -background transparent source.psd[0] -flatten  output.png
If that does not work, then post the original PSD file.

Please always provide your IM version and platform. Processing of PSD has been improved only in the last few releases.
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

I tried the exact command you gave and it gave a slightly different but still incorrect answer with the same RGB distortion.

Copyright Notice: This is owned by my company and I have permission to distribute this image for debugging purposed. This is not being released into the public domain and all rights are reserved

https://www.dropbox.com/s/1v99wscyqcva8h1/gun.psd?dl=0


Here is my version string:
Version: ImageMagick 6.9.6-4 Q16 x86_64 2016-11-10

Thanks for the help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by fmw42 »

One of the IM developers will need to look at this. I get an abort trap on IM 6.9.6.4 and IM 7.0.3.6 on Mac OSX with the following:

Code: Select all

convert gun.psd[0] gun.png
Abort trap

Code: Select all

identify -verbose gun.psd[0]
Abort trap

But this may be a Mac only bug. Try the first command and see if it works for you
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

Are you sure you downloaded the file correctly? It downloaded and I did not see anything about an abort on the command line? Did you see if you could open it in preview after you downloaded it?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by fmw42 »

This may be a Mac Imagemagick only bug. One of the developers is working on it.

But try the first command and see if it works for you

Code: Select all

convert gun.psd[0] gun.png
What is your platform?
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

Yes, I am on mac. If it makes a difference, I have mine installed via the Homebrew package installer, so it could be a sub dependency versioning difference perhaps.

Code: Select all

brew install imagemagick
I am searching for a way to upgrade to V7 using homebrew to test there. If anyone else has V7 and can try this PSD, it would be very helpful too.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by snibgo »

On Windows 8.1, I don't get an abort trap.

With v6.9.5-3, I get a bad shadow. With v7.0.3-5, the result looks good.
snibgo's IM pages: im.snibgo.com
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

Thanks so much! I will work to get V7 installed and do it an alternate way if HomeBrew does not yet have an install formula. I will report back on the results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by fmw42 »

Does this work for you on the current IM 6.9.6.4?

Code: Select all

convert gun.psd[0] gun.png
If not, then perhaps the fix was only included in IM 7 and not backported to IM 6. Or perhaps as I said it is a Mac issue and won't work on IM 7. It did not for me. I got an abort trap again. I install via source.

It also might be a Mac version issue, since I am on an old snow leopard.
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

Wow this is terrible...
Apparently, both MacPorts and Homebrew install only Imagemagick 6. I attempted to install from source, but was having trouble getting all the dependencies lined up manually. (Does anyone have an automated way of doing IM7 on Mac???). So I gave up and downloaded the binary and installed it. It works great until you actually try to do something with it, then it just prints

Abort trap: 6

The new version: Version: ImageMagick 7.0.3-5 Q16 x86_64 2016-10-18

Really frustrated now because it seems there is no way to get this actually installed on OSX for V7. I am on macOS Sierra btw. Not sure where to go from here so if anyone has any tips, please let me know.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by snibgo »

Sorry, I know nothing about Macs.
snibgo's IM pages: im.snibgo.com
DnA915
Posts: 7
Joined: 2016-11-12T18:25:18-07:00
Authentication code: 1151

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by DnA915 »

So I booted up the old Ubuntu VM in VirtualBox and installed from source (which was exceptionally easy compared to all the Mac pain), and it works perfect on V7. Really wish the mac version of V7 would get some love from the devs, but for now, it looks like I'll be moving things back and forth between the VM. If anyone has tips on getting a smooth V7 Mac version working, please let me know. To everyone else, thanks for the help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha not being handled correctly when flattening a gradient from a PSD file

Post by fmw42 »

As far a I know neither Homebrew nor MacPorts install IM 7, only IM 6.That is why I have installed via source. If you are interested, see viewtopic.php?f=1&t=21502&p=88202&hilit ... rts#p88202
Post Reply