Skip to content

Instantly share code, notes, and snippets.

@ruandre
Last active February 7, 2022 18:15
Show Gist options
  • Save ruandre/01b4304f9dba4cf86590 to your computer and use it in GitHub Desktop.
Save ruandre/01b4304f9dba4cf86590 to your computer and use it in GitHub Desktop.
Adobe Photoshop script to resize images to fit inside a 1024px box.
/***************************
NOT MAINTAINED! from ~2015
****************************/
// photoshop script to resize images proportionally to fit inside a 1024px box i.e. longest side/edge will equal 1024px
// useful when scaling down many large photos for web use, simply toss in a batch action
var activeDoc = app.activeDocument
var docWidth = activeDoc.width
var docHeight = activeDoc.height
activeDoc.changeMode(ChangeMode.RGB)
activeDoc.flatten()
// only resize images with an edge greater than 1024px
if (docHeight.as('px') > 1024 || docWidth.as('px') > 1024) {
if (docHeight > docWidth) {
// portrait
activeDoc.resizeImage(
null, // width
UnitValue(1024, 'px'), // height
null, // resolution
ResampleMethod.BICUBIC
)
} else {
// landscape
activeDoc.resizeImage(
UnitValue(1024, 'px'), // width
null, // height
null, // resolution
ResampleMethod.BICUBIC
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment