Skip to content

Instantly share code, notes, and snippets.

@rileyjshaw
Created October 22, 2019 03:43
Show Gist options
  • Save rileyjshaw/dcceaf649be2d5c6288e308a10e88af5 to your computer and use it in GitHub Desktop.
Save rileyjshaw/dcceaf649be2d5c6288e308a10e88af5 to your computer and use it in GitHub Desktop.
Photoshop JS script to resize + frame a bunch of photos
// This is a Photoshop script, not React.
//
var white = new SolidColor();
white.rgb.hexValue = "ffffff";
app.backgroundColor = white;
var doc = app.activeDocument;
doc.changeMode(ChangeMode.RGB);
// Crop and resize.
doc.crop(doc.selection.bounds);
if (doc.height > doc.width) {
doc.resizeImage(UnitValue(1.6, "in"), UnitValue(2, "in"), 300, ResampleMethod.AUTOMATIC);
} else {
doc.resizeImage(UnitValue(2, "in"), UnitValue(1.6, "in"), 300, ResampleMethod.AUTOMATIC);
}
// Add the frame.
app.activeDocument.resizeCanvas(UnitValue(4, "in"), UnitValue(6, "in"));
// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 100;
options.format = SaveDocumentType.JPEG;
options.optimized = true;
var newName = "framed-" + doc.name;
doc.exportDocument(File(doc.path + "/" + newName), ExportType.SAVEFORWEB, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment