Forum: Ruby Get the size in pixels for a string

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4d3c4ad293c983f47f3eab02796eafc7?d=identicon&s=25 Stéphane Thibaudeau (Guest)
on 2006-03-29 16:42
(Received via mailing list)
Hi list !

Id like to know the width and height in pixels for a string given a
font family, size and style.
How could I do that ?

2e34f386b20cb7c11c4204d699babd78?d=identicon&s=25 Chris Alfeld (Guest)
on 2006-03-29 17:00
(Received via mailing list)
This is undoubtedly overkill, but:

require 'tk'

f ='Courier 10')
width = f.measure("Hi There!")
height = f.metrics.assoc('linespace')[1]
This topic is locked and can not be replied to.