Copy link to clipboard
Copied
Hello. I have a PSD file consisting of several layer groups. I'm trying to use the Photoshop JavaScript API to extract these layer groups into separate PSD files. This is the relevant section of my code:
const axios = require('axios');
...
let psdData = {
"inputs": [{
"href": presignedUrl,
"storage": "external"
}],
"options": <options>
},
"outputs": [{
"storage": "external",
"type": <PSD type>,
"href": uploadURL
}]
}
let config = {
method: 'post',
maxBodyLength: Infinity,
url: '<PSD service URL>',
headers: {
'Authorization': 'Bearer ' + aioToken,
'x-api-key': aioApiKey,
headers
},
data: JSON.stringify(psdData)
};
let resp = await axios.request(config);
Copy link to clipboard
Copied
I believe you want to use "Create renditions". The endpoint is https://image.adobe.io/pie/psdService/renditionCreate and it's documented here: https://developer.adobe.com/photoshop/photoshop-api-docs/api/#tag/Photoshop/operation/renditionCreat...
However, it doesn't look like it supports layer groups, just layer IDs/names, but if they are predictable as well as the groups, in theory that would work.
Copy link to clipboard
Copied
Hello. Thanks for your help. I finally achieved what I wanted by using /actionJSON. I found out that the layer groups were actually artboards. However, they seem to work the same way as layers and layer groups.
Just in case someone runs into the same issue, this is the solution I found:
This is my new code:
const axios = require('axios');
//...
const artboardNames = ["960x400", "1080x566", "1080x1350", "640x960", "960x1280", "1080x1920", "1940x180", "240x1200", "1280x960", "1600x500", "1080x1080", "1920x1080"];
artboardNames.forEach(async (artboardName) => {
const artboardsToRemove = artboardNames.filter(element => element !== artboardName);
const removeArtboardActions = artboardsToRemove.map((element) => ({ "_obj": "delete", "_target": [{ "_name": element, "_ref": "layer" }] }));
let psdData = {
"inputs": [{
"href": presignedUrl,
"storage": "external"
}],
"options": {
"actionJSON": [
...removeArtboardActions
]
},
"outputs": [{
"storage": "external",
"type": "image/jpeg",
"href": uploadURL
}]
}
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://image.adobe.io/pie/psdService/actionJSON',
headers: {
'Authorization': 'Bearer ' + aioToken,
'x-api-key': aioApiKey,
headers
},
data: JSON.stringify(psdData)
};
let resp = await axios.request(config);
//...
})
I know this is kinda involved, since it deletes the undesired artboards instead of simply exporting the desired one, but it meets my goals.
Maybe /renditionCreate would be a clearer way to achieve the same result. However, I also need to perform other actions on the same PSD (like text and background changes), and actionJSON allows me to do them all with a single endpoint instead of having to call different ones separately (like /text for the text, /renditionCreate for the renditions and /smartObject for the Smart Objects).
Copy link to clipboard
Copied
Very cool and thank you for sharing (this is the same person as above, I just accidentally used my personal account before).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now