The text width and height obtained through the API are not correct

The width and height of the text obtained through the API are different from the width and height displayed in the Photoshop Properties panel


Could it be that some values are in pixels while the others are in a different unit (i.e. cm or inches)?

How to convert to get the value on the ps Properties panel ?

  • Only the width and height of the text do not match

I assume the numbers in the layer’s API object are pixels, because that’s what Photoshop natively operates on (and you can tell that they match the top/bottom, left/right of the bounds, if you do the math). Have you checked what units you are set to in your Photoshop preferences (settings)? You can get those via API (documented here) , and you can use the API as well to convert, e.g. pixels to whatever unit is currently set (documented here)

… that said, it is a little odd how the panel’s values are super close to the pixel values :thinking:

In the case of text, getting layer information with batchPlay shows that there are bounds directly under layer and bounds under textKey.

API is probably looking at bounds directly under layer. If you calculate the width and height from textKey.bounds by yourself, it might match.

1 Like

I confirm that:

  • 99.999% of what’s in the PS API in terms of units of measurement is expressed in pixels.
  • Layer bounds and textKey bounds are two separate things.
  • There might be rounding errors in the conversion, although I don’t remember the textItem to have a bounds prop.
  • I didn’t find access to the textKey property

Photoshop API—UXP for Adobe Photoshop

  • I can’t find the textKey
  • The ps api seems to be using pixel units

Photoshop API—UXP for Adobe Photoshop
I use these apis to develop plug-ins. What apis do I need to use to get the correct width and height

Yes, we are talking about Photoshop API.

API does not contain all of Photoshop’s information. Please use batchPlay to get the missing properties.