Custom icon saving script is exporting PNGs at HUGE sizes?
Hello, I have a script which saves icons out at various sizes, the problem being is that there is odd behavior exhibited, such as:
A 22px by 22px png at 72dpi with a file size of 12.5Mb
Clearly there is some metadata or some such which must account for the inflated size. There just is not enough "physical" data there to generate that size. The other explanation is that my script is just all jacked up. If anyone could take a look and maybe see where I have gone wrong, I would appreciate it.
Entire .jsx:
#target 'photoshop'
//Array of desired resolutions
var resolutions = [1024, 912, 512, 152, 120, 114, 80, 76, 58, 50, 44, 40, 29, 25, 22];
//Variable reference to the current opened photoshop file
var doc = app.activeDocument;
var docPath = File(app.activeDocument.path + '/' + app.activeDocument.name);
//Create the GUI window
var appWindow = new Window('dialog', 'Icon Processor (ver. 1.0)');
//Styling the window
//Size (must use an window.onShow(){}; callback
appWindow.onShow = function(){appWindow.size = 'width: 230, height: 300';}
//The Create Directory input
var createDir = appWindow.add('statictext',undefined,'Create Folder Name:');
//Input textfield
var dirNameInpt = appWindow.add('edittext',undefined,undefined);
dirNameInpt.characters = 20;
dirNameInpt.active = true;
//var dirName = dirNameInpt.text;
//The Create Directory input
var createFile = appWindow.add('statictext',undefined,'Enter File Name:');
//Input textfield
var fNameInpt = appWindow.add('edittext',undefined,undefined);
fNameInpt.characters = 20;
//var fileName = fNameInpt.text;
//The execute button
var execBtn = appWindow.add('button',undefined,'Execute');
execBtn.onClick = function()
{
//Loop through the array of resolutions
for(var i=0; i<resolutions.length; i++)
{
//Resize the image by each resolution in the array set dpi to 72
doc.resizeImage(UnitValue(resolutions, 'px'), UnitValue(resolutions, 'px'), 72, ResampleMethod.BICUBIC, 100);
//Call the export PNG function for each resolution pass in the doc and name of the file as parameters
exPNG24(fNameInpt.text, dirNameInpt.text, resolutions);
closeFile();
openFile();
}
//Close the application window
appWindow.close();
};
//Close button
var closeBtn = appWindow.add('button',undefined,'Cancel');
closeBtn.onClick = function()
{
appWindow.close();
};
//Display the window
appWindow.show();
function closeFile()
{
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function openFile()
{
app.open(docPath);
doc = app.activeDocument;
}
function exPNG24(f,d,i)
{
var name = f;
var directory = d;
var i = i;
//Write a new file appending the file name with the resolution of the image
var folder = new Folder(doc.path + '/' + directory);
if(!folder.exists);
folder.create();
var file = new File(folder + '/' + name + '_' + i + '.png');
//These are the options for saving the PNGs
var options = new PNGSaveOptions();
options.format = SaveDocumentType.PNG;
//Use PNG-24
options.PNG8 = false;
//Preserve transparency
options.transparency = true;
options.interlaced = false;
options.embedColorProfile = false;
//Maximum quality and medium compression to keep file size low
options.quality = 100;
options.compression = 5;
//remove meta data
doc.info = null;
//Save the image
doc.saveAs(file, options, true, Extension.LOWERCASE);
// doc.exportDocument(file, ExportType.SAVEFORWEB, options);
}
//This doesn't work yet but not important as the window can be manually closed by pressing 'cancel'
appWindow.close();
