Last active
April 14, 2017 06:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, need a help for small photoshop script
worked image should save in between 960px to 4200
if Width of the document is in between of 960 to 4200px save as it is,
if Image is in between of 600 to 959 make it as 960px and save
if the image is more than 4200px make it as 4200px and save
save for web format
quality: 100,
formate: jpeg,
save location: create a folder name "Output" in the source folder and save images by the source file name it self
contact mail ID : [email protected]