Skip to content

Instantly share code, notes, and snippets.

@PierBover
Last active June 3, 2021 17:05
Show Gist options
  • Save PierBover/2748189c25dee4dfa195 to your computer and use it in GitHub Desktop.
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.
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);
}
@PierBover
Copy link
Author

Check this GIST for 2 resize versions and JPG saving
https://gist.github.com/PierBover/2ce931fd092c5cba99dc

@whatsnewsisyphus
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment