Scripting: Extracting layer width and height, TextSize

Community Beginner ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Hey there, 

 

I want to get the layer width and height for every layer and tried to do it with: 

 

 

layerWidth = layer.bounds[2].value - layer.bounds[0].value; 
layerHeight = layer.bounds[3].value - layer.bounds[1].value;

 

Which gives me the width and height, but with 2 pixels larger than what Photoshop tells me if I click on the layer information. I didn't found another way to get these information. 

 

And the second question is, that I want to get the text size, but instead of for example 12 pt I get 11.9999966430661 pt

 

var textSize = layer.textItem.size;

 

 

Can you help me ?

Thank you in advance

TOPICS
Actions and scripting

Views

92

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Have you set units to pixel and points in your script.   Where is this layer info you click the disagrees with layer bounds. You could round the point value you get to 12.

JJMack

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

I have set the units to pixels in the beginning, and I already tried to set it to points before I measure the text size, but I still get the same value. 
The layer information is listed at (  I hope I translate it in the right way, since I don't use Photoshop itself in English) attributes (on the right hand side) and there it says "translate". There are height and width listed. And these attribute values don't match the values of the scripted ones. 

Senira

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

The layer information is listed at  attributes (on the right hand side) and there it says "translate". There are height and width listed.

 

Where is the info listed on the right side of where what you mentioned you click on layer info where do you click? Where is Layer Info

 

if I click on the layer information. I didn't found another way to get these information."   Photoshop has things you can click on all over its UI. I do not know where this Layer Info click button is.  I have never seen  Layer bounds to be wrong.  It has not always been what I was expecting for Place does some strange scaling and layer bounds is the scaled image filed layer size which can be different then the object size because of the Object file print resolution is not the same as the current document print resolution.  Place was implemented so it would play better with other Adobe application. That add complexity to Photoshop makes dealing with Smart Object Layer harder then most know.  Be warned if you script place and script working on smart object layers you will encounter some problems because of how place and smart object were implemented. Also Adobe frame tool uses place you can encounter issues with frame layers. They are  a combined layer set and a smart object layer.

JJMack

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

s3niRa_0-1613485283126.png

I meant this window right here, which says, that my red circle has a

width= 376 Pixel 

height= 377 Pixel

But when I get this information with my script and therefor layer.bounds... it says

width= 378 Pixel 

height= 379 Pixel. 

And my question was, why there are these 2 additional pixels, which seem to be off, if I compare the information from the script with the ones in Photoshop itself?  

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

You seem to be referring to the properties panel. On My Windows 10 system Layer Bounds and the Properties panel have the same values for width and height and topt left x and y points

image.png

JJMack

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Thank you though, I actually don't know, why it is different in my case. 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines