PSD layers to PNG but same size for all 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
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

PSD layers to PNG but same size for all layers

Post by alexandervrs »

I am using ImageMagick via command line and I have a PSD file with 3 layers that I need to export each layer as a PNG file.

So I use,

Code: Select all

convert.exe test.psd dispose Background test.png
This exports the layers but the problem is that the layers are not the same size. I need a way for all the layers to be the size of the PSD canvas.

Seeing this question on stackoverflow does not help as each layer contains transparency and -coalesce breaks everything.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PSD layers to PNG but same size for all layers

Post by fmw42 »

I think you will need to use identify to check the sizes of each layer or just flatten them and get that size.

In unix syntax:

Code: Select all

size=`convert image.psd -flatten -format "%wx%h" info:`
convert image.psd ... -background ... -gravity ... -extent $size results.png
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

Re: PSD layers to PNG but same size for all layers

Post by alexandervrs »

Thanks, this seems to work fine.
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

Re: PSD layers to PNG but same size for all layers

Post by alexandervrs »

Actually -gravity seems to bug certain images. I had a 600x600 animation through the layers and it seems that it just placed the entire animation at the corner.

I used,

Code: Select all

convert.exe anim.psd -gravity NorthWest -dispose Background -extent 600x600 frame.png
No matter if I remove -gravity or not, the result seems the same...

Image

You can see that at frame-0.png which is the entire image flattened, the images are aligned correctly. But all the individual frames are wrongly cropped again.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PSD layers to PNG but same size for all layers

Post by Bonzo »

I think you need to link to an animation others can try.
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

Re: PSD layers to PNG but same size for all layers

Post by alexandervrs »

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PSD layers to PNG but same size for all layers

Post by Bonzo »

This works for me ( puts the image in the centre of the canvas ) but I do not think it is what you want?
Do you still want your images in the relative positions as they are in the animation. e.g. frame-5 will be at the top of the image in the centre?

php method!

Code: Select all

$size = exec("convert anim.psd -flatten -format \"%wx%h\" info:");
exec("convert anim.psd -background white -gravity center -extent $size results.png");
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

Re: PSD layers to PNG but same size for all layers

Post by alexandervrs »

Yeah, I do need the images in the relative positions. The result would be if I manually saved the layers from the PSD file as PNGS without any trim/crop.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PSD layers to PNG but same size for all layers

Post by snibgo »

How about:

Code: Select all

convert -dispose Background anim.psd -layers coalesce f.png
snibgo's IM pages: im.snibgo.com
alexandervrs
Posts: 7
Joined: 2014-07-05T09:00:56-07:00
Authentication code: 6789

Re: PSD layers to PNG but same size for all layers

Post by alexandervrs »

This method worked fine, thanks snibgo.
Post Reply