Export files wtih PSD resolution

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

jacks_bfa

Export files wtih PSD resolution

Post by jacks_bfa »

Dear,

I have a script which is giving me files with different sizes but all in 72 resolution only.

I want to customized it to export files with my psd resolution

------------ below is the script ---------------------


#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try{
var Path = activeDocument.path;
}catch(e){
alert("Please save this file then re-run the script!");
return;
}
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
/*
make below code active if your text style not looking good, but with this way .png icon will create without transperancy

app.activeDocument.flatten();

*/
snapShot();
var saveFile = File(Path + "/" + Name + "_512x512.png");
activeDocument.resizeImage(512, 512, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
revertToLastSnapshot();
var saveFile = File(Path + "/" + Name + "_114x114.png");
activeDocument.resizeImage(114, 114, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
revertToLastSnapshot();
var saveFile = File(Path + "/" + Name + "_72x72.png");
activeDocument.resizeImage(72, 72, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
revertToLastSnapshot();
var saveFile = File(Path + "/" + Name + "_57x57.png");
activeDocument.resizeImage(57, 57, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
revertToLastSnapshot();
var saveFile = File(Path + "/" + Name + "_48x48.png");
activeDocument.resizeImage(48, 48, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
revertToLastSnapshot();
var saveFile = File(Path + "/" + Name + "_29x29.png");
activeDocument.resizeImage(29,29, undefined, ResampleMethod.BICUBICSHARPER);
SavePNG(saveFile);
app.preferences.rulerUnits = strtRulerUnits;
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function SavePNG(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG;
pngOpts.PNG8 = false; // true = png-8;false = png-24
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
function snapShot() {
var desc9 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putClass( charIDToTypeID('SnpS') );
desc9.putReference( charIDToTypeID('null'), ref5 );
var ref6 = new ActionReference();
ref6.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );
desc9.putReference( charIDToTypeID('From'), ref6 );
desc9.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );
executeAction( charIDToTypeID('Mk '), desc9, DialogModes.NO );
};
function revertToLastSnapshot() {
var doc = app.activeDocument;
var hsObj = doc.historyStates;
var hsLength = hsObj.length;
for (var i=hsLength - 1;i>-1;i--) {
if (hsObj.snapshot) {
doc.activeHistoryState = doc.historyStates.getByName('Snapshot ' + i);
break;
}
}
};