How to determine percentage increase of canvas in photoshop javascript

I am a javascript beginner, I have this bit of code in a jsx script that I would like to resize the canvas +20 percent on the horizontal and vertical sides.

resizeCanvas = docRef.resizeCanvas(curWidth + 20, curHeight + 20, AnchorPosition.MIDDLECENTER);

      

20 refers to any part on which the ruler is installed. (inches, pixels, centimeters, etc.).

What's the correct way to resize the canvas to 20 percent?

I suspect I might have to change the units before resizeCanvas to Units.PERCENT and then revert back to the default after resizing. It seems to print a lot to me, is there a better way?

+2


a source to share


2 answers


I would do it like this:

resizeCanvas = docRef.resizeCanvas(curWidth * 1.2, curHeight * 1.2, AnchorPosition.MIDDLECENTER);

      



You may need to use Math.round

or Math.floor

to force the width and height to be integers if the function resizeCanvas

does not handle this automatically.

+3


a source


This is what I came up with, is this the correct method?

var strtRulerUnits = app.preferences.rulerUnits; // store default ruler units

function resizecanvas(){
   app.preferences.rulerUnits = Units.PERCENT; // change units to percent
   docRef.resizeCanvas(curWidth + 20, curHeight + 20, AnchorPosition.MIDDLECENTER, ); // add 20 % to the canvas
   app.preferences.rulerUnits = strtRulerUnits; // restore to default ruler units
   }

      



resizeecanvas ();

+2


a source







All Articles