I've made a script which is being used in HTML panel for saving files as PNG or JPG based on selected option! below is my code.
function saveMain() {
var finalName = userName.replace(/ /g, "_").toLowerCase();
if (ext === ".png") {
var saveFile = new File(filePathFolder + "/" + finalName + ext);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
} else {
var saveFile = new File(filePathFolder + "/" + finalName + ext);
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 10;
app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
}
}
The Problem is my exported PNG side is way too big eg. 5.88 MB and the same file generated from save for web is only 38 KB! what am I missing in configuration! Thanks!
Edit : Problem is fixed by using ExportOptionsSaveForWeb instead of saveAs. but as Billy kerr pointed out even saving manually as Save As doesn't output such a big file so what is going on! use below code which trigerring sized PNG!
var saveFile = new File("~/Desktop/test.png");
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);