Skip to main content
Participant
January 8, 2019
Question

layer.bounds is different from bounds in Photoshop

  • January 8, 2019
  • 3 replies
  • 3508 views

I have this document:

The Transform show the X, Y, W, and H:

However, when calling this script:

var doc = app.activeDocument

var layer = doc.layers[0]

alert(layer.bounds[0])

alert(layer.bounds[1])

alert(layer.bounds[2])

alert(layer.bounds[3])

I get this:

X: 389 px

Y: 311 px

W: 4111 px

H: 751 px

As you can see, this differs from the X, Y, W, and H that I received from the Transform.

Why is this?

Looking at the text layer in Photoshop, it appears the blue outline on the left side is offset from the actual text by some pixels. It also appears to be offset from the top and bottom sides, but not the right side.

I would like the layer bounds to be consistent from Photoshop to my script. I am not sure if this is possible, however.

This topic has been closed for replies.

3 replies

Kukurykus
Legend
January 8, 2019

What about your answer or / and marking someone's correct solution in this topic?

pixxxelschubser
Community Expert
Community Expert
January 8, 2019

The real layer bounds are always the same as if your text is selected (marked with text tool).

If you want the visible bounds:

Make a copy of your textlayer --> raster --> get the bounds of the copied layer (--> if necessary remove the copied layer)

davescm
Community Expert
Community Expert
January 8, 2019

Hi
I've moved your post to the Photoshop Scripting forum where you are more likely to get a response to your question

Dave