I have the following code :
Code: Select all
require 'RMagick'
image=Magick::Image.new 320,100
draw=Magick::Draw.new
draw.font 'Arial'
draw.font_size 75
draw.text 10,10,'RMagick'
size=draw.get_type_metrics image,'RMagick'
draw.stroke 'black'
draw.fill_opacity 0
draw.rectangle 10,10,10+size['width'],10+size['height']
draw.draw image
image.display
p size
Code: Select all
#<struct Magick::TypeMetric pixels_per_em=#<struct Magick::Point x=12, y=12>, ascent=11.0, descent=-3.0, width=46.0, height=14.0, max_advance=24.0, bounds=#<struct Magick::Segment x1=1.0, y1=-2.0, x2=8.21875, y2=9.0>, underline_position=-4.5625, underline_thickness=-4.5625>
If I change the font and font_size, the rendered string changes accordingly. But the width and height returned by get_type_metrics remains the same 46.0 and 14.0. ( If I change the string, the width and height is calculated for the given number of characters, but the font is never taken in consideration. )
I would say, this is a bug, as similar code in PHP with IMagick works as expected when using queryFontMetrics().
Is there a solution/correction/workaround for this, to get the real text size ?
Thank you.
Additional information :
- Operating system : Linux
- ImageMagick version : 6.6.4-2
- RMagick version : 2.13.1