The width and height of the text obtained through the API are different from the width and height displayed in the Photoshop Properties panel
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 ?
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
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.
I confirm that:
textKey
bounds are two separate things.textItem
to have a bounds
prop.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.