Syntax error Measure text height on an HTML5 canvas element

Measure text height on an HTML5 canvas element



To get the text height, set the font in pt −

context.font="15pt Calibri";

Now, get the height like the following −

var height = parseInt(context.font.match(/\d+/), 10);

Above we have used a match to separate the font size from font face.

Updated on: 2020-06-25T07:12:51+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements