Command for ignoring Alpha Channel in PSD?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
RaoulDuke
Posts: 5
Joined: 2019-03-20T01:42:55-07:00
Authentication code: 1152

Command for ignoring Alpha Channel in PSD?

Post by RaoulDuke » 2019-03-20T02:09:36-07:00

Hi!

My company's using ImageMagick to create renditions in Adobe Experience Manager.
Most of our fundamental product images are in PSD format, and some of these contain an (hidden) Alpha Channel that's been rendered out and we want to keep for future purposes. These images contain freestanding product shots, with no background. From these PSD's the system creates PNG, and JPG renditions (for thumbnail and preview).

When the renditions are currently created, ImageMagick always applies the Alpha Channel and creates transparency in the PNG and a white background in the JPG where the Alpha Channel is.

How can I let ImageMagick ignore the Alpha Channel, but keep the transparency that's in the image for the PNG?

I'm afraid that applying -alpha off in PSD means no transparency at all.

Could alpha-unblend=off do the trick?

I'm confused and want to be sure, as I don't want to mess up all the hundreds of PNG images that are already on there...

Thanks a lot!

Raoul

User avatar
fmw42
Posts: 25742
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command for ignoring Alpha Channel in PSD?

Post by fmw42 » 2019-03-20T09:28:13-07:00

Please always provide your IM version and platform. Also your ImageMagick command line. And if possible post a link to one of your PSD files that has this issue so we can test with your image and examine it.

Just keep the alpha channel for PNG if that does not cause issues. For JPG, it does not support transparency, so you can flatten the PSD against some background color for whatever background you want to show. For PNG, you can also flatten it agains transparency so that it will keep the transparency.

One question -- is there background transparency and also an alpha channel? That is why I would like to see your PSD file.

RaoulDuke
Posts: 5
Joined: 2019-03-20T01:42:55-07:00
Authentication code: 1152

Re: Command for ignoring Alpha Channel in PSD?

Post by RaoulDuke » 2019-03-21T00:50:50-07:00

You're right. I've to check with out developers on the IM version and exact command lines. If you mean AEM by platform, it's 6.2.
Hope they can provide the answers in a timely manner... But!

Instead of providing a huge PSD, I think the issue is best explained with a simplified visual example I made:

Image

Yes, there's both a background transparency, as well as an Alpha Channel. The problem is that the Alpha Channel isn't always equal to the background transparency.

Furthermore, let's say the circle in this example also had a transparent shadow and reflection, this would be currently 'masked' by the Alpha Channel.
So background transparency yes, but ignore Alpha Channel that's the goal.

Hope that makes sense, and thanks for your reply. Much appreciated.

RaoulDuke
Posts: 5
Joined: 2019-03-20T01:42:55-07:00
Authentication code: 1152

Re: Command for ignoring Alpha Channel in PSD?

Post by RaoulDuke » 2019-03-21T02:03:53-07:00

ImageMagick version is 7.0.5-4

User avatar
fmw42
Posts: 25742
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command for ignoring Alpha Channel in PSD?

Post by fmw42 » 2019-03-21T09:07:22-07:00

It would be best if you post a link to your PSD file or a simple one that shows the problem so I can test with it. In the mean time I will try to generate a test PSD and see what I can figure out.

Did you try:

psd:alpha-unblend=off Disables new automatic un-blending of transparency with the base image for the flattened layer 0 before adding the alpha channel to the output image. This define must be placed before the input psd image. (Available as of IM 6.9.2.5). The automatic un-blending is new to IM 6.9.2.5 and prevents the transparency from being applied twice in the output image. This option should be set before reading the image.

RaoulDuke
Posts: 5
Joined: 2019-03-20T01:42:55-07:00
Authentication code: 1152

Re: Command for ignoring Alpha Channel in PSD?

Post by RaoulDuke » 2019-03-21T09:11:00-07:00

Cool! I'll send this info to our developers... A bit weird maybe, but my wife is about to have a baby any moment now! So, I'm off the radar for a bit... Again, super thanks for your help! Cheers!

User avatar
fmw42
Posts: 25742
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command for ignoring Alpha Channel in PSD?

Post by fmw42 » 2019-03-21T17:28:16-07:00

I was asking what platform you are using for ImageMagick.

I am not a PS expert. I have spent hours trying to replicate something like an image with background transparency and one red circle. I cannot figure out how to do that with PS CC. I can create the layer mask, but not the red circle on background transparency. So unless you provide me with that PSD file or instruct me how to do it, I am helpless to go any further.

RaoulDuke
Posts: 5
Joined: 2019-03-20T01:42:55-07:00
Authentication code: 1152

Re: Command for ignoring Alpha Channel in PSD?

Post by RaoulDuke » 2019-03-29T06:39:27-07:00

I'm back...and a father of a baby girl!

Here's the code we use:

magick ${filename}[0] -scale "1920x1920>" -quality 95 -profile "/opt/aem/sRGB_Profile.icc" -set filename:imgsize %w.%h ${filename}.Auto.%[filename:imgsize].png

magick ${filename}[0] -scale "1920x1920>" -quality 95 -layers flatten -background white -alpha remove -profile "/opt/aem/sRGB_Profile.icc" -set filename:imgsize %w.%h ${filename}.Auto.%[filename:imgsize].jpg

I'm hooking you up with a PSD in a PM.

User avatar
fmw42
Posts: 25742
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command for ignoring Alpha Channel in PSD?

Post by fmw42 » 2019-03-29T09:28:58-07:00

No PSD file was included in the PM. See my reply to your PM.

User avatar
fmw42
Posts: 25742
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Command for ignoring Alpha Channel in PSD?

Post by fmw42 » 2019-04-01T10:28:10-07:00

How can I let ImageMagick ignore the Alpha Channel, but keep the transparency that's in the image for the PNG?
It seems to do that for me on IM 6.9.10.35 Q16 Mac OSX and IM 7.0.8.35 Q16

Code: Select all

convert rd_circle_example.psd[0] result.png
I suggest you upgrade. Your version of IM 7 is rather old.

I tested with IM 7.0.5.4 and that worked for me also. I see no signs that the alpha channel was used to make the top of the circle transparent.

What is your platform/OS and date of the IM version? And how did you install IM?

This command also works for me.

Code: Select all

magick rd_circle_example.psd[0] -set filename:imgsize %w.%h -scale "1920x1920>" -quality 95 -profile "/Users/fred/images/profiles/sRGB.icc"  rd_circle_example.Auto.%[filename:imgsize].png

Post Reply