How to obtain the current layer size

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

meiyunyou
Posts: 20
Joined: Tue May 26, 2020 9:11 am

How to obtain the current layer size

Post by meiyunyou »

How to obtain the current layer size

Gets the current high layer width size
Request to give me an example

Thank you very much

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

lee ky
Posts: 22
Joined: Tue Mar 03, 2020 3:59 am

Re: How to obtain the current layer size

Post by lee ky »

function getLayerSizeToCopy(){

var layer = activeDocument.activeLayer; //Grab the currently selected layer



// Calculate length and width based on the rectangular bounds of the selected layer

var length = layer.bounds[2]-layer.bounds[0]; //Grab the length

var width = layer.bounds[3]-layer.bounds[1]; //Grab the width



// Remove pixels from the length/width "200 px" => "200"

length = length.toString().replace(' px', '');

width = width.toString().replace(' px', '');



prompt( "Layer Size: ", length + ", " + width );

}

getLayerSizeToCopy();
meiyunyou
Posts: 20
Joined: Tue May 26, 2020 9:11 am

Re: How to obtain the current layer size

Post by meiyunyou »

Thank you, thank you very much
User avatar
Stephen_A_Marsh
Posts: 38
Joined: Sun Aug 04, 2019 12:37 pm

Re: How to obtain the current layer size

Post by Stephen_A_Marsh »

One can also use

Code: Select all

.value
to remove the unix suffix:

https://gist.github.com/MarshySwamp/342 ... 3ef5b456ba