photoshop-python-api
photoshop-python-api copied to clipboard
How To calculate a text item's bounding box ?
trafficstars
Is there a way to calculate a text's real bounding box?
@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