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

Export as PNG via GUI and Script Produces Files in Different Sizes

Explorer ,
Apr 07, 2020 Apr 07, 2020

Hi,

 

I have a Photoshop file at https://www.dropbox.com/s/0kr95lj5o43brze/daccr.psd?dl=0


When export it as PNG, using "File" -> "Export" -> "Quick Export as PNG-8", I will get a PNG of 16.7k. See https://www.dropbox.com/s/5xfrhmub6moj98q/daccr%28quick-export%29.png?dl=0

 

When using "File" -> "Export" -> "Export As" and set the output format as PNG and check "Smaller File(8-bit)", I will get the same result.

 

However, when I using the following script to export the file into PNG format, 

 

var BoxshotFile = File("E:\\daccr.psd");
var BoxshotDoc = app.open(BoxshotFile);

SaveForWebAsPNG (BoxshotDoc, "E:\\daccr(script).png", 100);

// Save the PSD file
BoxshotDoc.close(SaveOptions.SAVECHANGES);
BoxshotFile.close();

 

function SaveForWebAsPNG(doc, filename, quality)
{
var outFile = new File(filename);
if (outFile.exists) {
outFile.remove();
}

var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.PNG;
sfwOptions.PNG8 = true;
sfwOptions.transparency = true;
sfwOptions.quality = quality;

doc.exportDocument (outFile, ExportType.SAVEFORWEB, sfwOptions);
}

 

I will get a PNG file of size 21 kb. See https://www.dropbox.com/s/kucn5q97324icjq/daccr%28script%29.png?dl=0

 

Why the GUI operation and script will produce difference results?

TOPICS
Actions and scripting
717
Translate
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 ,
Apr 07, 2020 Apr 07, 2020

The legacy ducky "save for web" engine is really old, from back when there was a separate sister program to Photoshop named ImageReady.

 

The new export/quick export feature uses different code, and is not yet available to scripting.

 

So you are not comparing apples to apples.

Translate
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
Explorer ,
Apr 07, 2020 Apr 07, 2020

Hi, Stephen_A_Marsh, 

 

Thank you for your reply. Then is it possible to batch export multiple files from PSD to PNG? It is really inconvenient to save many files into PNG one by one if no script can be used.

Translate
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 ,
Apr 07, 2020 Apr 07, 2020
LATEST

Export > Save for Web and Save As can both be scripted. It is only the newer export as that can't be recorded in an action or script (unless CC 2020 has changed that).

 

Why reinvent the wheel? Install this:

 

https://sourceforge.net/projects/ps-scripts/files/Image%20Processor%20Pro/v3_2%20betas/

 

 

Translate
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