From what I understand about canvas,
- Identify a board with size
- Then we can only draw it
But I'm trying to reach
- Draw text
- Measure text size
- Determine 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 a way to measure the size of the text and dynamically adjust the size of the canvas?
This is my demonstration, I define a canvas without any size and draw on it, but the canvas is large and has a lot of extra space. I am trying to make div div and canvas match content size
http://jsfiddle.net/5877a4aq/2/
source
share