• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Save to PNG options

New Here ,
Aug 10, 2019 Aug 10, 2019

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

TOPICS
Actions and scripting

Views

1.3K

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
community guidelines
Adobe
Community Expert ,
Aug 10, 2019 Aug 10, 2019

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:

  • 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.

Votes

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
community guidelines
New Here ,
Aug 10, 2019 Aug 10, 2019

Copy link to clipboard

Copied

Thanks Stephen,

Unfortunately now I got an error:

Error 2: pngOptions is undefined.

Line: 21

-> pngOptions.compression = 5;

Votes

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
community guidelines
Advocate ,
Aug 11, 2019 Aug 11, 2019

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

}

Votes

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
community guidelines
New Here ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Aug 11, 2019 Aug 11, 2019

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

Votes

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
community guidelines
Community Expert ,
Aug 11, 2019 Aug 11, 2019

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

JJMack

Votes

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
community guidelines
New Here ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

That's the line 62 which I posted earlier:

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

Votes

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
community guidelines
Community Expert ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines