Skip to main content
Participant
April 14, 2017
Question

Resize Canvas to 800x800 and Transform Rectangular Image to fit in those bounds

  • April 14, 2017
  • 3 replies
  • 1968 views

I keep trying to do this, using this script batch odd dimension images to square  for reference and I can't manage to get it...

What I want to do--for instance--is take a 1000x800 image, resize the canvas to 800x800, and then transform the image so that it is centered. So it becomes an 800x640 image and the 640 is centered.

It seems like this is a PERFECT task for scripting but I can't manage it right now. Can anyone help me out? Thanks so much in advance!

This topic has been closed for replies.

3 replies

JJMack
Community Expert
Community Expert
April 15, 2017

A simple action that you can batch will do it.  The tricky part is recording the Canvas size step so that 800 width and height are both recorded. Record

Step 1 Flatten (so canvas added will be filled with the background color)

Step 2 File>Automate>Fit Image... width and height set 800px. (Images aspect will be maintained so there no distortion The resulting image width or height may be less than 800 px.

Step 3 Canvas size 800px wide 800 px hight, (You must force this step to recorde correctly.) Stop recording before recording the Canvas Size step. Crop the fitted  work image to a smaller size so both the width and height are less the 800px.  Then click the record icon and record the Canvas size step 800px by 800ps leave the anchor point in the center and select the background color you want.

Stop recording the action is complete.

JJMack
Jarda Bereza
Inspiring
April 14, 2017

Menu > File > Automate > Fit Image...

c.pfaffenbichler
Community Expert
Community Expert
April 14, 2017

But to get a final square one would need to add a Canvas Size operation (in an Action for example).

c.pfaffenbichler
Community Expert
Community Expert
April 14, 2017

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var theTarget = 800;

// get longer side;

var theFactor = theTarget / getTheLonger(Number(myDocument.width), Number(myDocument.height));

// resize;

myDocument.resizeImage (myDocument.width * theFactor, myDocument.height * theFactor, myDocument.resolution, ResampleMethod.BICUBICAUTOMATIC);

myDocument.resizeCanvas (theTarget, theTarget);

// reset;

preferences.rulerUnits = originalRulerUnits;

}

else {};

function getTheLonger(a,b) {

  if (a >= b) {

  var x = a}

  else {

  var x = b};

  return x;

  };