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.
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 ?

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