What's the best way to generate image from text using JavaScript and HTML5 APIs?

I want to build a tool where a user can enter some text and I'll generate a JPEG/PNG on the fly with that text. How will you go about it? Is it possible with JavaScript alone?

Comments (2)

Tiago Sousa's photo

I think the best way would be to use the HTML5 API and then using the HTMLCanvasElement.toDataURL() function to convert the canvas to a image.

In this link you can see how select a font family, size and color and add it to a canvas. - w3schools.com/canvas/canvas_text.asp

Here is a quick example in JsFiddle of what you want

jsfiddle.net/17ut2kzm