Sha256: ff3efa8b3e45f83f96e449850e5ce02838e2fe07584a9abcee120945c783a1cc

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

require File.join(File.dirname(__FILE__), 'new_image.rb')

include Magick

TEXT = 'get\nmultiline\ntype\nmetrics'

background = Image.new(200, 200)
gc = Draw.new

# Draw the text centered on the background
gc.annotate(background, 0, 0, 0, 0, TEXT) do
    gc.font_family = 'Verdana'
    gc.pointsize = 36
    gc.gravity = CenterGravity
    gc.stroke = 'none'
end

# Get the metrics
metrics = gc.get_multiline_type_metrics(background, TEXT)

# Compute the corners for a rectangle surrounding the text
x = (background.columns - metrics.width) / 2
y = (background.rows - metrics.height) / 2

# Draw 2 rectangles over the text.
gc = Draw.new

gc.stroke('red')
gc.stroke_width(5)
gc.stroke_linejoin('round')
gc.fill('cyan')
gc.fill_opacity(0.10)
gc.rectangle(x, y, x+metrics.width, y+metrics.height)

gc.stroke('white')
gc.stroke_width(1)
gc.fill('none')
gc.rectangle(x, y, x+metrics.width, y+metrics.height)
gc.draw(background)


background.write('draw_multiline_type_metrics.jpg')

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rmagick4j-0.3.6 test/eyetests/tests/draw_multiline_type_metrics.rb