Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

image processing - Extract layers from PSD with ImageMagick, preserving layout

I'm using ImageMagick to extract layers from a PSD, and it gets them all out fine with:

convert image.psd image-%d.png

But the resulting PNG images are of varying dimensions, depending on the actual contents of the layer. What I'd like is to extract all the layers, but have them all the same size, so that I can easily lay them on top of each other later, and have everything line up just as it did in the original PSD.

If it helps to visualise it, this is what I'm currently getting with the command above:

+----+
|A   |   +-+   +-+
|    | = |A| + |B|
|   B|   +-+   +-+
+----+

And what I want is:

+----+   +----+   +----+
|A   |   |A   |   |    |
|    | = |    | + |    |
|   B|   |    |   |   B|
+----+   +----+   +----+

With the resulting images having a transparent background so that I can do this:

+----+   +----+ 
|A   |   |A   |+
|    | = |    ||
|   B|   |   B||
+----+   +----+|
          +----+

I'm not in any way tied to ImageMagick, so if there's another (preferably command-line) tool that can achieve this, that's fine.

question from:https://stackoverflow.com/questions/6598848/extract-layers-from-psd-with-imagemagick-preserving-layout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Type this to extract the layer number 2 from a PSD file:

convert             
  <filename>.psd[0] 
  <filename>.psd[2] 
  (                    
     -clone 0           
     -alpha transparent 
  )                    
 -swap 0           
 +delete           
 -coalesce         
 -compose src-over 
 -composite        
 <extracted-filename>.png

This creates first a transparent canvas with the same size of the PSD file, then combines it with the layer 2 keeping it's original layout (-coalesce)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...