PSD layers to PNG, trimming based on opacity of composite image including hidden layers

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
elmimmo
Posts: 26
Joined: 2011-02-02T05:42:42-07:00
Authentication code: 8675308

PSD layers to PNG, trimming based on opacity of composite image including hidden layers

Post by elmimmo »

I want to export PSD layers to PNG, maintaining the layers' layout (i.e. keeping transparent areas in each one so that stacking them back still produces the original illustration), but still trimming out areas that would be transparent in their composite version including layers which are hidden in the original PSD.

The following command

Code: Select all

convert IN.PSD OUT.PNG
extracts all layers keeping their layout but

• the composite image of all visible layers is created too, with suffix 0, which I do not need nor want.
• each layer trims areas that are transparent only on itself. I want to trim transparent areas common to all layers, visible and invisible.

This other command

Code: Select all

convert IN.PSD -set dispose Background -coalesce OUT.PNG
accomplishes the same but trims nothing at all.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PSD layers to PNG, trimming based on opacity of composite image including hidden layers

Post by snibgo »

I'm not sure, but the following might extract all layers except number 0:

Code: Select all

convert IN.PSD[1--1] OUT.PNG
"1--1" means start at number 1, and stop at the last one.

If this gives all the layers, including "invisible" layers, you can "-layers merge" them, and "-format %@" will tell you what the trim boundaries of that image would be. You can then trim all the layers with that crop specification.
snibgo's IM pages: im.snibgo.com
Post Reply