converting PSB/PSD files with layer masks

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
paulheckbert
Posts: 5
Joined: 2011-01-05T08:58:39-07:00
Authentication code: 8675308

converting PSB/PSD files with layer masks

Post by paulheckbert »

One of the principal reasons for using Photoshop PSB or PSD format is its support for layers. But as far as I can tell, convert is unable to properly flatten a PSB or PSD that uses layer masks.

For example, in http://db.tt/JoFppTLt you'll find several files

heads1_mask.psb
heads1_applymask.psb

and ppm versions of these files created using, e.g.

convert -flatten heads1_mask.psb heads1_mask.ppm

heads1_mask.ppm shows buggy results
heads1_applymask.ppm shows the desired results

I tested with Version: ImageMagick 6.7.2-0 2012-02-25 Q16 http://www.imagemagick.org

The heads1_mask.psb file has two layers with layer masks indicating partial transparency (what you typically want to do, when editing layers) composited over a background image. All three layers are RGB 8 bit. This image was not saved with a compatibility layer.

When you do a convert, as above, the mask is erroneously ignored (treated as opaque everywhere) for one layer, and the other layer appears to be suffering from decompression errors (the y coordinates are correct, but pixels have the wrong x coordinate, or color, or transparency).

Changes that DO NOT cause the bug to disappear:
Adding a compatibility layer.
Saving in PSD format instead of PSB.
Hide one layer (scrambled pixel effect remains).
Delete a layer (this causes the scramble to go away, but the mask is still incorrectly ignored).

Changes that DO cause the bug to disappear:
Do "Layer / Layer Mask / Apply" to each layer (I'd prefer that I not be forced to ask our users to do this to all their PSB files.) The heads1_applymask.psb was created this way.
Do "Layer / Layer Mask / Delete" to each layer (but this changes the composite image).
Do "Layer / Flatten" (but that's why I was running convert in the first place...).

In the tests I've done, it appears that PSB/PSD files with two layers with layer mask typically result in the masks being ignored, and three or more layers with layer mask result in masks being ignored and layers getting scrambled. I've never seen convert do a correct job of flattening a PSB or PSD file that uses layer masks.

This looks like a fundamental bug in ImageMagick's PSB/PSD support. Could it be fixed?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: converting PSB/PSD files with layer masks

Post by magick »

We find PSD one of our most difficult formats to support. We make bug fixes / enhancements from time-to-time but have not found the time to properly support this format. We're currently in the middle of developing ImageMagick 7.0.0 so it may be some time before we can come up with a proper patch for your bug report. If anyone in the development community would like to support the PSD format, let us know.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting PSB/PSD files with layer masks

Post by fmw42 »

Paul,

I am not an expert on PSD or PSB files. I have only an old PS CS. But your psb images display fine in my PS. But looking at the number of layers in heads1_applymask.psb, PS reports 3 layers and heads1_mask.psb shows 5 layers with two extra linked to the first two overlay layers.

However, IM identify only recognizes 4 layers for both images.

For heads1_applymask.psb, if I do

convert heads1_applymask.psb heads1_applymask_%d.png

then I see the first [0] layer as a white background, the [1] layer your full background image and [2] and [3] as your overlay layers with transparency.

IM handles this file just fine. Note the proper IM 6 syntax reads the image first then flattens it. Your syntax is IM 5 legacy syntax, however, it should still work. see http://www.imagemagick.org/Usage/basics/#cmdline

convert heads1_applymask.psb -flatten heads1_applymask2.ppm


With regard to your second image, heads1_mask.psb

convert heads1_mask.psb heads1_mask_%d.png

generates 4 images (and not six). The first is the white background, the second is your background image, the third is your face image without any transparency and the fourth is the face and hand image without any transparency, but it has streaks in it and it looks corrupt.
Flattening them, just produces the same result you get.

So it looks like IM cannot handle the linked layers that you have for masking the other two layers and ignores (?) them.


I have to admit that IM's handling of PS PSD or PSB images is still lacking in many regards. I have already reported a number of problems. This includes issues with grayscale PSD images and with the issue of IM not being able to handle both background transparency and alpha transparency simultaneously. Only one or the other is chosen and that is not an option controlled at this time by the user.

I believe that the main issue is a lack of contributors who are experts at PSD and PSB images along with the available time for the limited staff to attend to all the outstanding bugs.

However, I will certainly defer to the IM developers for further comments and corrections to my statements.

Fred
paulheckbert
Posts: 5
Joined: 2011-01-05T08:58:39-07:00
Authentication code: 8675308

Re: converting PSB/PSD files with layer masks

Post by paulheckbert »

Fred/fmw42:
Thanks for the tips on argument order.

In case it wasn't clear: the PSB files I supplied were created using Photoshop CS5. They look fine in Photoshop CS5 and they both show 3 layers there. I've been trying to get "convert -flatten" to work properly on PSB files. It fails on heads1_mask.psb.

I'm concluding that:
1) ImageMagick cannot read mask layers in PSB/PSD correctly.
2) Don't trust "convert -flatten" on PSB/PSD files if mask layers are used.
3) Better to use "convert x.psb[0] x.ppm" instead of "-flatten", but this will only work if the file was saved with a compatibility layer.

I wish I'd known the above a year ago; it could have saved me a week or two of development time.

The documentation should be changed to warn others. http://www.imagemagick.org/script/formats.php currently has no comments about limitations of PSB & PSD support. Perhaps those comments should say something like "The composite image, accessible as filename.psb[0], can be read reliably, if the file was saved in Photoshop with 'maximize compatibility'. Image masks are not fully supported."

I sympathize with anyone trying to make sense of PSB/PSD format; it appears quite complex, and Adobe's secrecy & litigiousness makes things worse.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting PSB/PSD files with layer masks

Post by fmw42 »

The documentation should be changed to warn others. http://www.imagemagick.org/script/formats.php currently has no comments about limitations of PSB & PSD support. Perhaps those comments should say something like "The composite image, accessible as filename.psb[0], can be read reliably, if the file was saved in Photoshop with 'maximize compatibility'. Image masks are not fully supported."
Paul,

I have had the same issue both with the PS compatibility checkbox and also with its save transparency checkbox.

With all these combinations, it seems very hard to support everything that Adobe puts into PS. Non-standard layers and layer groups are also a problem.

I have spent many days without complete success just trying to get IM to re-create something that looks like what PS displays due especially to the problems with compatibility mode and background vs alpha channel transparency.

With the development of IM 7 allowing an arbitrary number of channels, I have hopes that PSD, PSB and TIFF handling will eventually improve. If you know of anyone with expertise in PSD, PSB and TIFF formats, that would be willing to help the IM team, I believe that they would be very happy for the help.

Since PS CS3, I understand that they have even changed the brightness contrast function to some non-linear adjustment. However, they still have a legacy mode there. But many users are now building actions with the newer mode. According to changes that I have read, they have also changed how exposure works and some people are not happy with that.

Fred
Post Reply