Last active
June 3, 2021 17:05
-
-
Save PierBover/2748189c25dee4dfa195 to your computer and use it in GitHub Desktop.
Conditional resize image script for Photoshop. No save, only resize to desired area.
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 image = app.activeDocument; | |
var imageRatio = image.width / image.height; | |
// change this to true if you want to upscale if the image is smaller than the desired area | |
var upscale = false; | |
var area = { | |
width: 700, | |
height: 500 | |
}; | |
area.ratio = area.width / area.height; | |
var scale; | |
if(imageRatio >= area.ratio){ | |
scale = area.width / image.width.value; | |
} else { | |
scale = area.height / image.height.value; | |
} | |
if (upscale) { | |
image.resizeImage(UnitValue(image.width * scale,"px"),UnitValue(image.height * scale,"px"),null,ResampleMethod.AUTOMATIC); | |
} else if(scaleThumb < 1){ | |
image.resizeImage(UnitValue(image.width * scale,"px"),UnitValue(image.height * scale,"px"),null,ResampleMethod.AUTOMATIC); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no scaleThumb, I am guessing you meant scale on line 24, also you can just combine the conditional to if (upscale or scale < 1)