Skip to main content
iMiKE
Participant
August 8, 2011
Question

[SOLVED] Adaptive resize action (script)

  • August 8, 2011
  • 1 reply
  • 1272 views

Hello!

I'm writing my set of PS-actions for automatic retouch elements.

So, how to add adaptive resize to action or script?

What is adaptive resize - horizontal foto resizes to 1000*500px and vertical foto to 500*1000px, for example, in one script/action.

Curently I need to separate my files into two sets - horiz and vert fotos and process them separately with 2 actions.

But I want process them in one action in one flow((

So, plese, can someone help me?

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
August 8, 2011

In this case using File > Automate > Fit Image might suffice.

Are the images’ proportions always 2:1 or 1:2 or would that need consideration, too?

iMiKE
iMiKEAuthor
Participant
August 8, 2011

c.pfaffenbichler, yepp, image proportions always fixed 1:2 and 2:1 and size also fixed.

Hmmm...thanks for clue. It might be enough.

c.pfaffenbichler
Community Expert
Community Expert
August 9, 2011

This should also work.

Though proper Scripting should probably also include a check for the correct proportions.

// 2011; use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

// set to pixels;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// get dimensions;

var myHeight = myDocument.height;

var myWidth = myDocument.width;

// scale;

if (myHeight > myWidth) {

     var myScale = new UnitValue (10000 / myHeight, "%");

     myDocument.resizeImage(myScale, myScale, undefined, ResampleMethod.BICUBIC)

     }

else {

     var myScale =  new UnitValue (100000 / myWidth, "%");

     myDocument.resizeImage(myScale, myScale, undefined, ResampleMethod.BICUBIC)

     };

// reset;

app.preferences.rulerUnits = originalRulerUnits;

};