Last active
December 25, 2021 21:09
-
-
Save npanuhin/4c5439f6c38fe77f70d29e7597e6dc13 to your computer and use it in GitHub Desktop.
Resize Photoshop image to specified resolution
This file contains 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
// These are values for the end result width and height (in pixels) of our image | |
// | |
// Common values: | |
// Vk.com max photo size: 2560 x 2160 | |
var target_width = 1920; | |
var target_height = 1080; | |
// ======================================================================================== | |
#target photoshop | |
app.preferences.rulerUnits = Units.PIXELS; | |
var doc = app.activeDocument, | |
cur_width = doc.width, | |
cur_height = doc.height; | |
// Test height resize | |
var height_resize_new_height = target_height; | |
var height_resize_new_width = Math.round(cur_width * height_resize_new_height / cur_height); | |
// Test width resize | |
var width_resize_new_width = target_width; | |
var width_resize_new_height = Math.round(cur_height * width_resize_new_width / cur_width); | |
if (height_resize_new_width >= target_width) { | |
doc.resizeImage(null, UnitValue(target_height, "px"), null, ResampleMethod.AUTOMATIC); | |
} else { | |
doc.resizeImage(UnitValue(target_width, "px"), null, null, ResampleMethod.AUTOMATIC); | |
} | |
doc.resizeCanvas(UnitValue(target_width, "px"), UnitValue(target_height, "px")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment