Skip to content

Instantly share code, notes, and snippets.

@opengeek
Last active March 9, 2022 19:26
Show Gist options
  • Save opengeek/8721056df91449cd2e1897aed7de7c05 to your computer and use it in GitHub Desktop.
Save opengeek/8721056df91449cd2e1897aed7de7c05 to your computer and use it in GitHub Desktop.
Use Photoshop scripting to adjust any image that exceeds Instagram aspect ratios by padding the canvas size with white background color.
var docRef = app.activeDocument;
var currentWidth = docRef.width;
var currentHeight = docRef.height;
var aspectRatio = currentWidth / currentHeight;
var mycolor = new SolidColor();
mycolor.rgb.hexValue = "ffffff";
app.backgroundColor = mycolor;
if (aspectRatio < 0.8) {
var paddedWidth = currentHeight * 0.8;
docRef.resizeCanvas(paddedWidth, currentHeight, AnchorPosition.MIDDLECENTER);
} else if (aspectRatio > 1.91) {
var paddedHeight = currentWidth * 1.91;
docRef.resizeCanvas(currentWidth, paddedHeight, AnchorPosition.MIDDLECENTER);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment