1

How to Batch Resize in Photoshop

This doesn't seem to work, so I think a script way might be what I need.

Adobe Photoshop Scripting

The resize method in its JavaScript reference guide doesn't seem to cover this (p.64).

(parts of the image can be hidden)

3
  • Could you add some examples of what you're trying to achieve and how the resize method in the javascript reference guide doesn't cover this? Apr 8, 2021 at 13:08
  • It sounds like something which can be done without a script simply using an action. What is the difference between "covering the whole canvas" and "fit shortest length"?
    – Wolff
    Apr 8, 2021 at 16:18
  • no difference .
    – Ryan Case
    Apr 21, 2021 at 7:28

2 Answers 2

1

Not entirely sure this is what you want....

If you want something to fill the canvas and maintain proportions, this script isn't for you.


I do this all the time. I struggled, like you, to find something that would not maintain proportions and merely fill the canvas, stretching or squishing as necessary.

I tried searching for where I may have originally found this script.. but honestly I have no clue. I may have even edited or corrected something else I found. It's been years since I first started using this script.

var doc = app.activeDocument;
var layer = doc.activeLayer;
layer.translate(new UnitValue(0-layer.bounds[0].as('px'),'px'), new UnitValue(0-layer.bounds[1].as('px'),'px'));
layer.resize((doc.width.value/(layer.bounds[2]-layer.bounds[0]))*100,(doc.height.value/(layer.bounds[3]-layer.bounds[1]))*100,AnchorPosition.TOPLEFT);

Will move a layer to top left corner of canvas, then resize to fill the canvas, not maintaining any proportion.

Note that nothing will be "hidden" using this script. When the script is called, all pixels on the highlighted layer in the Layer Panel will be forced to the canvas boundaries, regardless of what that does to the original proportions.

(If the original author presents themselves I'm happy to credit them.)

3
  • how to make it maintain proportion and resize the longer length to fit the canvas so that some parts can be hidden(fill the canvas)?
    – Ryan Case
    Apr 9, 2021 at 3:04
  • ermm ... you linked to viable answers to that question in the original question post.... but you need to start thinking of resizing the short edge , not the long edge if you want the canvas filled with cropping. Using the long edge will always leave empty spaces.
    – Scott
    Apr 9, 2021 at 8:01
  • oh yeah. what do you mean viable answers?
    – Ryan Case
    Apr 10, 2021 at 7:30
0

Here you go:

var doc = app.activeDocument;
var layer = doc.activeLayer;

var b = layer.bounds;
var layer_width  = b[2] - b[0];
var layer_height = b[3] - b[1];


// put the layer in center

var layer_center_x = b[0] + layer_width/2;
var layer_center_y = b[1] + layer_height/2;

var doc_center_x = doc.width/2;
var doc_center_y = doc.height/2;

var shift_x = doc_center_x - layer_center_x;
var shift_y = doc_center_y - layer_center_y;

layer.translate(shift_x, shift_y);


// scale the layer

var scale_w = doc.width  / layer_width;
var scale_h = doc.height / layer_height;
var scale = Math.max(scale_w, scale_h)*100;

layer.resize(scale, scale, AnchorPosition.MIDDLECENTER);

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.