Agamnentzar / ag-psd

Javascript library for reading and writing PSD files
Other
490 stars 66 forks source link

How can I extract multi layers and output one image? #129

Closed CavellHuang closed 5 months ago

CavellHuang commented 1 year ago

Is there any way I can select multi layers and composite them as one image?

Agamnentzar commented 1 year ago

The PSD file contains image for each layer and a composite image of the entire drawing. If you want to create composite image of only some of the layers, you'd have to composite them yourself, probably using something like node-canvas (or HTML canvas element in a browser)

CavellHuang commented 1 year ago

Can I do it by modifying psd document such as set the layer I don't want to output hidden, or use the layer canvas that psd document already had.

Agamnentzar commented 1 year ago

You can read canvas of each layer and composite canvas of the whole document from the PSD file, but if you modify the document the canvases will no longer be correct and you have to update them yourself this library will not modify them for you. You can't modify the document and then read the composite canvas because it will be the old version of the canvas.

CavellHuang commented 1 year ago

You can read canvas of each layer and composite canvas of the whole document from the PSD file, but if you modify the document the canvases will no longer be correct and you have to update them yourself this library will not modify them for you. You can't modify the document and then read the composite canvas because it will be the old version of the canvas.

You can read canvas of each layer and composite canvas of the whole document from the PSD file, but if you modify the document the canvases will no longer be correct and you have to update them yourself this library will not modify them for you. You can't modify the document and then read the composite canvas because it will be the old version of the canvas.

Wath bothers me is how should I update the composite canvas if I modify the document. Do you have any ideas? Thanks so much!

Agamnentzar commented 1 year ago

If the document is very simple you can use basic functionality of HTML canvas (or node-canvas in nodejs) https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial

If the document is complex and uses more features you'll have to reimplement portions or entirety of Photoshop rendering engine.

CavellHuang commented 1 year ago

If the document is very simple you can use basic functionality of HTML canvas (or node-canvas in nodejs) https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial

If the document is complex and uses more features you'll have to reimplement portions or entirety of Photoshop rendering engine.

ok, I will try it. Thanks again for your answer.