Issue Flattening PSD to JPG with multiple alpha channels

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
peterb

Issue Flattening PSD to JPG with multiple alpha channels

Post by peterb »

Hello,

I'm experiencing a curious issue when using convert to flatten a photoshop file containing 2 alpha channels into a JPG. The two channels are, for lack of better names, the "primary" (the intrinsic channel produced when on removes the background in photoshop), and a "user defined" channel (created when a user explicitly creates a new channel in photoshop). Despite this user defined channel being hidden, the two are still being oddly combined on flatten, producing a strange artifact. Illustrative blurry blobs bellow:

Image with intrinsic alpha:
Image

Hidden user alpha:
Image

Image flattened using photoshop:
Image

Image flattened to jpg using convert -flatten (ImageMagick 6.5.4-10)
Image

The PSD in question is here.

Is this a bug, or am I just misusing convert? If I could find a way to detect and strip that user defined channel, guess that would be a workaround, but I am unsure how to go about doing that. Any help would be much appreciated.

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by magick »

Try this command:
  • convert 'redblackthing.psd[1]' redblackthing.png
peterb

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by peterb »

Thanks for the speedy reply,
magick wrote:Try this command:
  • convert 'redblackthing.psd[1]' redblackthing.png
This sort of works ... it does produce a clean image BUT also clips the completely transparent edges of the image, changing its size and requiring some extra steps to reconstruct the dimensions and positioning of the original. I know, I know, beggars can't be choosers.

Also, how did you know to use layer/frame 1?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by fmw42 »

try this

convert redblackthing.psd[0] -background white -flatten -quality 100 redblackthing.jpg

The first (zero) frame of the psd generally contains the composite of all the other channels.
peterb

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by peterb »

fmw42 wrote: convert redblackthing.psd[0] -background white -flatten -quality 100 redblackthing.jpg

The first (zero) frame of the psd generally contains the composite of all the other channels.
Sadly fmw42, no dice:
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by anthony »

Reading PSD images is tricky, The file format usually starts with a 'pre-flattened' image as the first (zeroth) image, followed by the other images. It looks like that the hidden alpha image is then stored as a the second image simply as a mask.

Can you get use the number of images IM reads from the PSD, and a copy of what each image is? Also what is it you desire to do with the 'hidden alpha' image?
Junk it? Replace the current alpha? Merge with the current alpha? What?

What do you want?

You haven't actually told us, so everyone is just sort of guessing!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by fmw42 »

fmw42 wrote:try this

convert redblackthing.psd[0] -background white -flatten -quality 100 redblackthing.jpg

The first (zero) frame of the psd generally contains the composite of all the other channels.

Strange as this is what I get (IM 6.5.4-10 Q16 HDRI Mac OSX Tiger):

Image
peterb

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by peterb »

anthony wrote:The file format usually starts with a 'pre-flattened' image as the first (zeroth) image, followed by the other images. It looks like that the hidden alpha image is then stored as a the second image simply as a mask.

Can you get use the number of images IM reads from the PSD, and a copy of what each image is?
If I'm interpreting convert correctly only 2 images are detected (ie, it only addresses redblackthing.psd[0] and redblackthing.psd[1]). Looks like you, anthony (and fmw42) are correct, the first image (redblackthing.psd[0]) is indeed 'pre-flattened' and a direct conversion produces exactly what I want!

convert redblackthing.psd[0] -quality 100 redblackthing.jpg
Image

Oddly, its only when I add an explicit -flatten to the first image that things go awry ... though, maddeningly, only for me (fmw42 - I got that result twice using a slightly older build (IM 6.5.1-0 2009-04-20 Q16) on linux and the latest binary (IM 6.5.4-10 Q16) on windows ... maybe we have different configs?).

anthony wrote: Also what is it you desire to do with the 'hidden alpha' image?
Junk it? Replace the current alpha? Merge with the current alpha? What?

What do you want?

You haven't actually told us, so everyone is just sort of guessing!
I apologize if I wasn't completely clear - I just want convert -flatten to work as expected, producing the same results flattening a simple psd as one would get from photoshop. I don't care what happens to the hidden alpha, I just want it to stay hidden during the the flattening process, which is not currently happening.

Now, if my expectations are wrong, and I should just always be using the first (zero) image of a psd instead of -flatten, that's a different matter...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by fmw42 »

suspect you need to upgrade to 6.5.4-10 as there may be bugs or differences in older versions of IM
peterb

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by peterb »

fmw42 wrote:suspect you need to upgrade to 6.5.4-10 as there may be bugs or differences in older versions of IM
A reasonable concern, which is why I sanity checked with the latest (6.5.4-10) binary on windows and still got the same result. So strange. Looks like extracting (but not flattening!) the first (zero) image is my solution for now.

Still, this is a much better solution than I had before. Thanks for the help everyone.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue Flattening PSD to JPG with multiple alpha channels

Post by fmw42 »

certainly does not explain why this works for me on IM 6.5.4.-10 Q16 (HDRI) and I don't think it has anything to do with the HDRI

convert redblackthing.psd[0] -background white -flatten -quality 100 redblackthing.jpg

perhaps it is your libjpeg?

(I am using libjpeg-6b.tar.gz)
Post Reply