How to put, render, write or draw text in canvas tag using drawText function in JavaScript.
HTML:
Create a HTML file and put a canvas tag in it. Give it a size and we are off to write some JavaScript to render the text.Source code viewer
<canvas id="canvas_text" width="250" height="250"></canvas>Programming Language: XML
JavaScript:
Of course you have to put JavaScript in script tag. But this example code writes your test in your string in to canvas tag.If you play with the parameters you can see how the text changes.Source code viewer
var canvas_text = document.getElementById("canvas_text").getContext("2d"); //font = 'size font-family' canvas_text.font = '20pt Arial'; //fillText(string, x, y) canvas_text.fillText('Hello, world!', 50, 25);Programming Language: Javascript