Copy link to clipboard
Copied
Hello all, I am trying to make a small script that resizes a layer (shrinking) to fit the canvas/image size... I am trying to do this by querying both the document width/height then comparing it to the layer width/height, but I cannot find any way to find the layer width/height... any suggestions? I have tried the code below but it brings back an 'undefined'.
app.preferences.rulerUnits = Units.PIXELS;
var docHeight = app.activeDocument.height;
//alert(docHeight);
var docWidth = app.activeDocument.width;
//alert(docWidth);
var layerWidth = app.activeDocument.activeLayer.width;
alert(layerWidth);
//this line above returns the 'undefined"
How can I get the activeLayer width and height?
Thanks!
var theBounds = app.activeDocument.activeLayer.bounds;
var layerWidth = theBounds[2] - theBounds[0];
var layerHeight = theBounds[3] - theBounds[1];
Copy link to clipboard
Copied
It's layer.bounds. I'm not into PS scripting, but I know at least that much. Hope it helps.
Mylenium
Copy link to clipboard
Copied
var theBounds = app.activeDocument.activeLayer.bounds;
var layerWidth = theBounds[2] - theBounds[0];
var layerHeight = theBounds[3] - theBounds[1];
Copy link to clipboard
Copied
+ - - - - - - - 1 - - - - - - - +
| |
| |
| |
0 2
| |
| |
| |
+ - - - - - - - 3 - - - - - - - +
Thanks SuperMerlin!
Copy link to clipboard
Copied
It's Left, Top, Right and Bottom
Find more inspiration, events, and resources on the new Adobe Community
Explore Now