#target photoshop
var doc = app.activeDocument;
if (doc == null) {
throw "No Valid document available for export.";
}
if (doc.width != doc.height) {
throw "Image is not square";
}
var startState = doc.activeHistoryState; // save for undo
var initialPrefs = app.preferences.rulerUnits; // will restore at end
app.preferences.rulerUnits = Units.PIXELS; // use pixels
// Folder selection dialog
var destFolder = Folder.selectDialog( "Select Output folder");
// Save icons in PNG using Save for Web.
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.PNG;
sfw.PNG8 = false; // use PNG-24
sfw.transparency = true;
doc.info = null; // delete metadata
var icons = [
{"name": "ic_launcher", "folder_name":"drawable-ldpi","size":36},
{"name": "ic_launcher", "folder_name":"drawable-mdpi","size":48},
{"name": "ic_launcher", "folder_name":"drawable-hdpi","size":72},
{"name": "ic_launcher", "folder_name":"drawable-xdpi","size":96},
{"name": "ic_launcher120x120", "folder_name":"Others","size":120},
{"name": "ic_launcher144x144", "folder_name":"Others","size":144},
{"name": "ic_launcher512x512", "folder_name":"Others","size":512},
];
var icon;
for (i = 0; i < icons.length; i++) {
icon = icons[i];
//Resolution was 72 while creating the psd for the images.
doc.resizeImage(icon.size, icon.size, null, ResampleMethod.BICUBIC);
var destFileName = icon.name + ".png";
var folderPath = new Folder(destFolder + "/" + icon.folder_name);
if(!folderPath.exists)
folderPath.create();
doc.exportDocument(new File( folderPath + "/"
+ destFileName), ExportType.SAVEFORWEB, sfw);
doc.activeHistoryState = startState; // undo resize
}
alert("Android Icons created!");
if (doc != null) {
doc.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = initialPrefs; // restore prefs
}
I am trying to automate the behavior of "save for web" in Photoshop. I am successful in creating images but its producing low quality image. I am a newbie here. Not sure what is going wrong. If i do it the usual gui way, it generates the good quality.