Working on aio app builder(asset compute worker) to integrate the Photoshop action api. I have the Photoshop action file which has to do the below actions
I have configured the processing profile to call the appbuilder worker code with the photoshop action file. I am getting the output rendition in the form of psd and png.. but i can able to see that psd rendition is not having the mask applied and png rendition is not having the transparent background. Getting background removed for both the psd and png rendition. When i check the same photoshop action file in the adobe photoshop, its working fine. my doubt is do we need to separate logic in the worker code. below is my piece of code. And i noticed the property of the asset in aem, it is showing the type as image/jpeg..
async function setupPhotoshopActionsOptions(client, instructions, files) {
if (!instructions || !instructions.photoshopActions) {
throw Error("Photoshop Action URL not provided");
}
let photoshopActions = instructions.photoshopActions;
let ext;
try {
ext = path.extname(photoshopActions).substring(1).toLowerCase();
} catch (err) {
console.log("Error extracting the file name");
}
if (!ext) {
const tempActionFilename = `${uuidv4()}_temp.atn`;
const aioLibActionFilename = `${uuidv4()}/photoshopActions.atn`;
await downloadFile(photoshopActions, tempActionFilename);
await files.copy(tempActionFilename, aioLibActionFilename, { localSrc: true });
photoshopActions = aioLibActionFilename;
}
const options = {
actions: [{
href: photoshopActions
}]
};
if (options && Array.isArray(options.actions) && instructions.photoshopActionsName) {
options.actions[0].actionName = instructions.photoshopActionsName;
}
return options;
}
exports.main = worker(async (source, rendition, params) => {
const { orgId, apiKey, accessToken } = getAuthorization(params);
let files = await Files.init();
const client = await sdk.init(orgId, apiKey, accessToken, files);
const fmt = rendition.instructions.fmt || "jpg";
const tempFilename = `${uuidv4()}/rendition.${fmt}`;
const options = await setupPhotoshopActionsOptions(client, rendition.instructions, files);
const result = await client.applyPhotoshopActions(source.url, tempFilename, options);
console.log('Response from Photoshop API', result);
if (result && result.outputs && result.outputs[0].status === 'failed') {
const errors = result.outputs[0].errors;
console.error('Photoshop API failed:', errors);
throw new Error(`Photoshop API failed: ${errors.code} ${errors.title}`);
}
console.log("Photoshop actions are successful:", rendition.path);
if (fmt === 'psd') {
try {
const psdTempFilename = `${uuidv4()}/rendition.psd`;
const psdOptions = {
...options,
outputType: "psd", // Request PSD output with layers intact
layers: true, // Ensure layers are retained
};
const result = await client.applyPhotoshopActions(source.url, psdTempFilename, psdOptions);
console.log("Photoshop API Result for PSD:", result);
if (result && result.outputs && result.outputs[0].status === 'failed') {
const errors = result.outputs[0].errors;
console.error('Photoshop API failed:', errors);
throw new Error(`Photoshop API failed: ${errors.code} ${errors.title}`);
}
await files.copy(psdTempFilename, rendition.path, { localDest: true });
await files.delete(psdTempFilename);
console.log("PSD rendition completed successfully");
} catch (error) {
console.error("Error processing PSD rendition:", error);
throw error;
}
} else if (fmt === 'png') {
try {
const pngTempFilename = `${uuidv4()}/rendition.png`;
const pngOptions = {
...options,
outputType: "png", // Ensure PNG output with transparency preserved
preserveTransparency: true // Explicitly state to preserve transparency
};
const result = await client.applyPhotoshopActions(source.url, pngTempFilename, pngOptions);
console.log("Photoshop API Result for PNG:", result);
if (result && result.outputs && result.outputs[0].status === 'failed') {
const errors = result.outputs[0].errors;
console.error('Photoshop API failed:', errors);
throw new Error(`Photoshop API failed: ${errors.code} ${errors.title}`);
}
await files.copy(pngTempFilename, rendition.path, { localDest: true });
await files.delete(pngTempFilename);
console.log("PNG rendition completed successfully");
} catch (error) {
console.error("Error processing PNG rendition:", error);
throw error;
}
} else {
try {
await files.copy(tempFilename, rendition.path, { localDest: true });
await files.delete(tempFilename);
console.log("JPG rendition completed successfully");
} catch (error) {
console.error("Error processing JPG rendition:", error);
throw error;
}
}
}. Its really helpful if you could help me to get a solution. Thanks in advance!
Regards,
Bhavani Bharanidharan