Skip to content

Instantly share code, notes, and snippets.

@davidmerrique
Last active April 14, 2017 06:17
Show Gist options
  • Save davidmerrique/4066808 to your computer and use it in GitHub Desktop.
Save davidmerrique/4066808 to your computer and use it in GitHub Desktop.
Photoshop Script to save multiple sizes of an image. I use it for work.
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder !== null) {
var fileList = inFolder.getFiles(/\.(jpg|tif|psd|)$/i);
var outfolderName = prompt('Folder name', 'zoom');
var outfolder = new Folder(decodeURI(inFolder) + "/" + outfolderName);
if (!outfolder.exists) outfolder.create();
for(var a = 0; a < fileList.length; a++) {
if(fileList[a] instanceof File) {
var doc = open(fileList[a]);
var docname = fileList[a].name.replace(/\.[^\.]+$/, '');
zoomify();
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
function zoomify() {
var savedRuler = app.preferences.rulerUnits;
var w = app.activeDocument.width;
var h = app.activeDocument.height;
var quality = 50;
app.preferences.rulerUnits = Units.PIXELS;
if(w > h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
if(w < h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
app.activeDocument.resizeImage('2560px', undefined, undefined, ResampleMethod.BICUBICSHARPER);
app.preferences.rulerUnits = savedRuler;
for(var i = 4; i >= 0; i--) {
var outfolder = new Folder(decodeURI(inFolder) + "/" + outfolderName + "/" + docname + "/TileGroup0");
if (outfolder.exists === false) outfolder.create();
var saveFile = new File(decodeURI(outfolder) + "/" + i + "-0-0.jpg");
SaveJPEG(saveFile, quality);
app.activeDocument.resizeImage('50%','50%', undefined, ResampleMethod.BICUBICSHARPER);
quality = quality + 10;
}
}
function SaveJPEG(saveFile, quality) {
var exportOptionsSaveForWeb = new ExportOptionsSaveForWeb();
exportOptionsSaveForWeb.format = SaveDocumentType.JPEG;
exportOptionsSaveForWeb.includeProfile = false;
exportOptionsSaveForWeb.interlaced = true;
exportOptionsSaveForWeb.optimized = true;
exportOptionsSaveForWeb.quality = quality;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB,exportOptionsSaveForWeb);
}
@mankan2727
Copy link

contact mail ID : mail4manikanta@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment