-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How To calculate a text item's bounding box ? #198
Comments
@wantsjean you can try below codes. from photoshop import Session
with Session() as ps:
doc = ps.active_document
layer = doc.activeLayer
print(layer.textItem.size)
print(layer.bounds) |
@wantsjean If you're trying to get the dimensions of the bounding box of the text item, you can do: height, width = layer.textItem.height, layer.textItem.width This is for the bounding box, but if you want the dimensions of JUST the text without the spacing of the bounding box: def get_layer_dimensions(layer):
"""
Compute the width and height dimensions of a layer.
@param layer: A layer object
@return dict: Height and width of the layer.
"""
return {
'width': layer.bounds[2]-layer.bounds[0],
'height': layer.bounds[3]-layer.bounds[1],
} If you're talking about the vertices of the bounding box on a grid, use hal's answer, you can use layer.bounds to construct coordinates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to calculate a text's real bounding box?
The text was updated successfully, but these errors were encountered: