Specifying compression in PNGSaveOptions broken?
Hello, I have a simple save-as-png script which I've been using without issue since the CS5 days. More recently, my studio has upgraded our computers and software, which resulted in upgrading from CC 2015.x to 19.1.6. The old script still functions, however, PS ignores the explicit compression setting within the script and simply uses whatever compression setting I last used when saving as, through the UI. E.g. if my script specifies compression = 0 (no compression) or if the property isn't specified at all (default is no compression), it will still use maximum compression if that happened to be the option chosen on my last trip through the UI's Save As function.
This is costing me a lot of time due to repeated failures, long save times, and troubleshooting, and I'd like to understand how fix my script. My intention is to quickly save PNGs with no compression (large file) and no dialogue boxes or menus. Any help or insight would be appreciated.
Thanks,
Derek
app.displayDialogs = DialogModes.NO;
var saveOptions = new PNGSaveOptions();
saveOptions.compression = 0;
saveOptions.interlaced = false;
fileCheck();
// Functions
function fileCheck(){
if (documents.length == 0) {
alert("No documents open - Aborted");
return;
}
else if (isDocumentNew()){
alert("Unsaved file - Aborted");
return;
}
else {
runSave();
}
}
function isDocumentNew(doc){
// assumes doc is the activeDocument
cTID = function(s) { return app.charIDToTypeID(s); }
var ref = new ActionReference();
ref.putEnumerated( cTID("Dcmn"),
cTID("Ordn"),
cTID("Trgt") ); //activeDoc
var desc = executeActionGet(ref);
var rc = true;
if (desc.hasKey(cTID("FilR"))) { //FileReference
var path = desc.getPath(cTID("FilR"));
if (path) {
rc = (path.absoluteURI.length == 0);
}
}
return rc;
};
function runSave(){
var filePath = app.activeDocument.path;
var fileName = app.activeDocument.name.replace(".psd", "");
fileName = app.activeDocument.name.replace(".png", "");
var fileFolder = Folder(filePath);
if(!fileFolder.exists) fileFolder.create();
savePNG(new File(filePath + "/" + fileName));
}
function savePNG(saveFile) {
app.activeDocument.saveAs(saveFile, saveOptions, true);
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
