Page 1 of 1
PSD layers to PNG but same size for all layers
Posted: 2014-07-05T09:06:38-07:00
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.
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-05T09:55:22-07:00
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
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-05T10:30:42-07:00
by alexandervrs
Thanks, this seems to work fine.
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T14:13:23-07:00
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...
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.
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T14:26:36-07:00
by Bonzo
I think you need to link to an animation others can try.
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T14:29:05-07:00
by alexandervrs
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T14:42:55-07:00
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");
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T15:20:24-07:00
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.
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T15:30:19-07:00
by snibgo
How about:
Code: Select all
convert -dispose Background anim.psd -layers coalesce f.png
Re: PSD layers to PNG but same size for all layers
Posted: 2014-07-06T17:19:39-07:00
by alexandervrs
This method worked fine, thanks snibgo.