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.
Stéphane Thibaudeau (Guest)
on 2006-03-29 18: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 ?

Chris A. (Guest)
on 2006-03-29 19: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.