Last active
August 29, 2015 14:20
-
-
Save danbjoseph/42e3e9fff62f706dae65 to your computer and use it in GitHub Desktop.
Photoshop script for thumbnail and small preview img
This file contains hidden or 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 = new Folder("~/Desktop/forUpload"); | |
var fileList = inFolder.getFiles(/\.(jpg|tif|psd|bmp|gif|png|pdf|)$/i); | |
for(var a = 0 ;a < fileList.length; a++) | |
{ | |
var docRef = open(fileList[a]); | |
// set background color | |
var color = app.backgroundColor; | |
color.rgb.red = 234; | |
color.rgb.green = 234; | |
color.rgb.blue = 234; | |
app.backgroundColor = color; | |
// get a reference to the current (active) document and store it in a variable named "doc" | |
doc = app.activeDocument; | |
// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results | |
doc.changeMode(ChangeMode.RGB); | |
// these are our values for the end result width and height (in pixels) of our image | |
var fWidth = 600; | |
var fHeight = 400; | |
//portrait mode, resize based on height | |
if (doc.height > doc.width) { | |
doc.resizeImage(null,UnitValue(fHeight,"px"),"200",ResampleMethod.BICUBIC); | |
} | |
else { | |
doc.resizeImage(UnitValue(fWidth,"px"),null,"200",ResampleMethod.BICUBIC); | |
} | |
// call autoContrast and applySharpen on the active layer. | |
// if we just opened a gif, jpeg, or png, there's only one layer, so it must be the active one | |
// doc.activeLayer.autoContrast(); | |
// doc.activeLayer.applySharpen(); | |
doc.resizeCanvas(new UnitValue(fWidth,"px"),new UnitValue(fHeight,"px"), AnchorPosition.TOPCENTER); | |
// our web export options | |
var options = new ExportOptionsSaveForWeb(); | |
options.quality = 100; | |
options.format = SaveDocumentType.JPEG; | |
options.optimized = true; | |
var smallName = doc.name.slice(0,-4) + '_small.jpg'; | |
doc.exportDocument(File(doc.path+'/'+smallName),ExportType.SAVEFORWEB,options); | |
fWidth = 300; | |
fHeight = 200; | |
//portrait mode, resize based on height | |
if (doc.height > doc.width) { | |
doc.resizeImage(null,UnitValue(fHeight,"px"),"200",ResampleMethod.BICUBIC); | |
} | |
else { | |
doc.resizeImage(UnitValue(fWidth,"px"),null,"200",ResampleMethod.BICUBIC); | |
} | |
doc.resizeCanvas(new UnitValue(fWidth,"px"),new UnitValue(fHeight,"px"), AnchorPosition.TOPCENTER); | |
var thumbName = doc.name.slice(0,-4) + '_thumb.jpg'; | |
doc.exportDocument(File(doc.path+'/'+thumbName),ExportType.SAVEFORWEB,options); | |
doc.close( SaveOptions.DONOTSAVECHANGES ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment