Created
November 12, 2023 10:02
-
-
Save steveruizok/8fc84900334028b705abcb724c8f98fb to your computer and use it in GitHub Desktop.
get the bounding box of a text shape?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTextBoundingBox(text: SVGTextElement) { | |
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg') | |
svg.appendChild(text) | |
document.body.appendChild(svg) | |
const bbox = text.getBoundingClientRect() | |
document.body.removeChild(svg) | |
return bbox | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment