Hi!
I have two ways of exporting a document to PNG-24 in UXP:
const localFS = require("uxp").storage.localFileSystem;
const folder = await localFS.getFolder({ initialDomain: domains.userDocuments });
const fileEntry = await folder.createEntry("mypng.png", { overwrite: true });
// Method 1
doc.saveAs.png(fileEntry, {
compression: 8,
method: constants.PNGMethod.QUICK,
});
// Method 2
const sessionToken = await localFS.createSessionToken(fileEntry);
await action.batchPlay(
[
{
_obj: "save",
as: {
_obj: "PNGFormat",
method: {
_enum: "PNGMethod",
_value: "quick"
},
PNGInterlaceType: {
_enum: "PNGInterlaceType",
_value: "PNGInterlaceAdam7"
},
PNGFilter: {
_enum: "PNGFilter",
_value: "PNGFilterAdaptive"
},
compression
},
in: {
_path: sessionToken,
_kind: "local"
},
documentID: docID,
copy: true,
lowerCase: true,
saveStage: {
_enum: "saveStageType",
_value: "saveBegin"
},
_options: {
dialogOptions: "dontDisplay"
}
}
],
{
modalBehavior: "execute"
}
);
However, I have trouble when trying to export the document as a PNG-8, like with the legacy Save for Web export.
doc.saveAs.png
doesn’t let me specify the bit-depth and I’ve had no luck with batchPlay at all.
let saveForWebOptions = {
_obj: "saveForWeb",
fileType: "PNG",
PNG8: (pngType === "PNG-8"),
transparency: true
};
// Add PNG-8 specific options if applicable
if (pngType === "PNG-8") {
saveForWebOptions.colors = 256;
saveForWebOptions.dither = "none";
}
// Construct the batchPlay descriptor
const command = {
_obj: "export",
using: saveForWebOptions,
in: {
_path: sessionToken,
_kind: "local"
},
_isCommand: true,
_options: {
dialogOptions: "dontDisplay"
}
};
const res = await action.batchPlay(
[
command
],
{
modalBehavior: "execute"
}
);
console.log(`res => ${JSON.stringify(res)}`);
This gives me:
exportPNG res => [{"_obj":"export","result":false,"onError":"One or more required values missing or incorrect for 'Export descriptor':, 'file', 'options', 'format'"}]
and I have no idea where to check the proper format. Alchemist and the Action recorder do not record when I export via the File > Export as menu.
What is interesting is that the Action recorder does record when I use the Export > Save for Web menu, but since it is marked as legacy, I’d like to avoid any problems with the possible deprecation.
Is there any way to get a 8-bit PNG file, or something equivalent with the default PNG-24, using UXP?