From what I understand about canvas ,
- Define a board with size
- Then we only can draw on it
But I am trying to achieve
- Draw the text
- Measure the text size
- Define the canvas size
HTML
<div style="background:grey;display:inline-block;">
<canvas id="samplecanvas" style="background:red;"></canvas>
</div>
Javascript
var c = document.getElementById("samplecanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World" ,10, 50);
Is there any way to measure the text size and dynamically adjust the canvas size?
This is my demostration , I define the canvas without any size and draw on it , but the canvas size is big and have many extra white space.I am trying to make the div and canvas expand accordingly to the content size