Save the image layer group
I have a PSD with layer groups. Is it possible to save each layer group as an image?
For Example: Layer group 01: { layer logo layer text to be continued.... } Layer group 02: { layer logo layer text to be continued.... }
I need to download each layer group as a separate image.
Have you found a solution?
I couldn't find a solution. I'm using the separate layers. Joining the single layers until they form a group of complete layers.
me to
I couldn't find a solution. I'm using the separate layers. Joining the single layers until they form a group of complete layers.
Hi, can you tell me how you join these layers? Thanks!
You will need to recursively go over the layers of the top node of the group you want to save and save each one of them over the parent node's image.
Example:
PSD.open('caminho do psd').then( async function (psd) {
/** Get info layer */
const node = psd.tree().descendants();
const contentInfo = await getinfoLayers(node);
)}
const getinfoLayers = async (node) => {
let content = []; // save all layers of each group
let contentGroup = []; // save all layer groups
let nameGroup = 0; // rename layer group
let lastnameGroup = 1; // rename layer
const fileLayers = join(__dirname,"../layers-all/") // base path
const searchForImage = async (node) => {
// does node contain children?
if (node && node.hasChildren()) {
nameGroup++;
lastnameGroup = 1;
if(nameGroup > 1){
content.push([...contentGroup]);
}
contentGroup = [];
await searchForImage(node.childeren);
}
else if (node) {
/** retun a Promise */
// save layer to path...
node.layer.image.saveAsPng(fileLayers+`${nameGroup}_${lastnameGroup}.png`);
/** set infor layers */
contentGroup.push({
name: `${nameGroup}_${lastnameGroup}`,
height: node.get('height'),
width: node.get('width'),
opacity: node.export().opacity,
coords: node.get('coords'),
text: node.export().text ? node.export().text : ''
});
lastnameGroup++;
}
}
await Promise.all( node.map( node => searchForImage(node)));
content.push([...contentGroup]);
console.log("Finish get infomations the layers...");
return content;
};
Another example: issue #143
After that you will have all the layers identified by group, that is: (01_01, 01_02, 02_01....).
Now you have the position information for each layer and can use some mechanism to join them together. It can be a library or canvas.