Skip to content

Instantly share code, notes, and snippets.

@argami
Created September 27, 2011 17:44
Show Gist options
  • Save argami/1245721 to your computer and use it in GitHub Desktop.
Save argami/1245721 to your computer and use it in GitHub Desktop.
Right measurement of text width on Javascript using canvas
measure_text: (text, font_size, font_family) ->
canvas = document.createElement('canvas')
ctx = window.canvas.getContext '2d'
ctx.font = "#{font_size} #{font_family}"
ctx.measureText(text).width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment