You can also render the text as a canvas element. Note how you can't drag and drop this element or open in a new tab, as opposed to a regular image.
This is also the only way to render text as an image that is not selectable in Safari!
Another way is to render the canvas back on a regular image element as a data URI.
Going even further - you can create a blob from the canvas and use that as the source for an image.
Emojis are also supported! 😊
As are structural elements like <p>
And lists
Built-in fonts are also supported. However, only the styles of the context node are picked up by default. Styles on individual elements inside the markup to render are lost:
You could of course compile them yourself and pass them in the styles-option
This example uses text from a script tag with a type that is not recognized by the browser. When using a method like this, you'll have to provide a good context node yourself, since the script tag likely has no styles:
The right column will render an image that was
entirely created from a string of text/markup.
Since no context node is provided, the image will
be rendered with the styles applied to document.body
.
Also I provide the forced width option to make the image only 300px wide.