Forum: Ruby Get the size in pixels for a string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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 ?

Thanks,
Stéphane.
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 = TkFont.new('Courier 10')
width = f.measure("Hi There!")
height = f.metrics.assoc('linespace')[1]
This topic is locked and can not be replied to.