Save to PNG options

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

Topics

Actions and scripting

Views

250

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More

Save to PNG options

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

Topics

Actions and scripting

Views

251

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More

Re: Save to PNG options

Adobe Community Professional , Aug 10, 2019

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:

  • typename
  • compression
  • interlaced

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

Thanks Stephen,

Unfortunately now I got an error:

Error 2: pngOptions is undefined.

Line: 21

-> pngOptions.compression = 5;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

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);

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

I got an error:

https://ibb.co/93f4pyD

I guess the error comes from this line:

//SAVE JPG

myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

Most Valued Participant , Aug 11, 2019

aaaa88840318  wrote

I got an error:

https://ibb.co/93f4pyD

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

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

// 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);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

Most Valued Participant , Aug 11, 2019

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

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

That's the line 62 which I posted earlier:

myDocument.saveAs((new File(thePath+"/"+basename+".png")),pngopts ,true);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...

Re: Save to PNG options

JJMack LATEST
Most Valued Participant , Aug 11, 2019

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

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn More
Reply
Loading...