Copy link to clipboard
Copied
Hi there,
Can anyone help with the script options to save PNG file? Basically I tired to replace a JPG save options to PNG save options but all I've got as a result is a blank PNG file and no image:
// JPG OPTIONS
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 10;
// PNG options
var pngopts = new PNGSaveOptions();
pngopts.PNG8 = true;
pngopts.transparency = true;
pngopts.interlaced = false;
pngopts.quality = 100;
I am not sure if these are the correct values. I will be grateful for any help you can provide.
Thanks,
Alex
Copy link to clipboard
Copied
As your results indicate, JPEG and PNG property options are not interchangeable.
The JS reference lists the following three PNGSaveOptions properties for the Document.SaveAs() method:
So:
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 5; // digit value of 0 - 9
pngOptions.interlaced = false; // boolean value of true or false
Not to be confused with the various property options that are applicable to the PNG format when using ExportOptionsSaveForWeb.
You can't mix-n-match these PNG properties, you either use PNGSaveOptions or you use ExportOptionsSaveForWeb.
Copy link to clipboard
Copied
Thanks Stephen,
Unfortunately now I got an error:
Error 2: pngOptions is undefined.
Line: 21
-> pngOptions.compression = 5;
Copy link to clipboard
Copied
See if this is good for you.
main();
function main(){
if(!documents.length) return;
try{
var Path= activeDocument.path;
}catch(e)
{var Path = "~/desktop";}
var subFolder = new Folder(activeDocument.path + '/PNG SAVE/')
if (!subFolder.exists){subFolder.create()};
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var saveFile= new File(subFolder + "/Name " + Name + ".png");
sfwPNG8(saveFile);
}
function sfwPNG8(saveFile){
var pngOpts = new PNGSaveOptions;
pngOpts.compression = 9;
pngOpts.interlaced = true;
activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);
}
Copy link to clipboard
Copied
I got an error:
I guess the error comes from this line:
//SAVE JPG
myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);
Copy link to clipboard
Copied
aaaa88840318 wrote
I got an error:
I guess the error comes from this line:
//SAVE JPG
myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);
Post the script that staemet
myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);
is in so we can see if it has set a var pngopts the error states that var is undefined
Copy link to clipboard
Copied
// PNG OPTIONS
function sfwPNG8(saveFile){
var pngOpts = new PNGSaveOptions;
pngOpts.compression = 9;
pngOpts.interlaced = true;
activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);
}
//SAVE PNG
myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);
Copy link to clipboard
Copied
So the error message is correct pngopts is undefined perhaps you ment to use pngOpts like in the save function you posted. However that var pngOpts is local to the save function you posted sfwPNG8. You should post your full script where your mydocument statement "myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);" is line 62.
the error you got was clear and specific not wrong
Copy link to clipboard
Copied
That's the line 62 which I posted earlier:
myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);
Copy link to clipboard
Copied
You did not post the full script. The error message states pngopts is undefined. You never defined a variable pngopts a png save options object