Sha256: 2dab2c497f6203e0760963fd877d69a45b0f69b5c4625ba97006993f5f36cf44

Contents?: true

Size: 1010 Bytes

Versions: 29

Compression:

Stored size: 1010 Bytes

Contents

#! /usr/local/bin/ruby -w
require 'RMagick'

TEXT = 'get\nmultiline\ntype\nmetrics'

background = Magick::Image.new(200, 200)
gc = Magick::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 = Magick::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 = Magick::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.border!(1,1, 'blue')

background.write('get_multiline_type_metrics.gif')

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
rmagick-2.13.4 doc/ex/get_multiline_type_metrics.rb
rmagick-2.13.3 doc/ex/get_multiline_type_metrics.rb
rmagick-2.13.3.rc1 doc/ex/get_multiline_type_metrics.rb
rmagick-2.13.2 doc/ex/get_multiline_type_metrics.rb
rdp-rmagick-0.0.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.13.1 doc/ex/get_multiline_type_metrics.rb
rmagick-2.12.2 doc/ex/get_multiline_type_metrics.rb
rmagick-2.12.1 doc/ex/get_multiline_type_metrics.rb
rmagick-2.12.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.11.1 doc/ex/get_multiline_type_metrics.rb
rmagick-2.10.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.11.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.2.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.0.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.1.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.2.2 doc/ex/get_multiline_type_metrics.rb
rmagick-2.3.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.4.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.5.0 doc/ex/get_multiline_type_metrics.rb
rmagick-2.5.1 doc/ex/get_multiline_type_metrics.rb