I have an application, that takes html as input, renders an image and saves it. It also requires the user to specify the width and height that the image should be. I want to automate the height and width part so the user wouldn't need to set it up manually
The Problem:
if the html is as simple as <p>text</p>
the height is pretty easy to find by using clientHeight
but the width will be the whole width of the viewport and most of it would be absolutely unneeded to show text
, so the picture would be very narrow (height = 16px; width = 1080px) and that is not great.
The Question:
is there any way to find the width of an element that it actually uses? (for instance width required by <p>text</p>
would be closer to 16px but not 1080px)