Text overlay using RMagick

July 13, 2007
Text overlay example

For what I’m doing (simple text overlay on an image) this is the setup I’m using. This is based on an article I saw using something to autogenerate images for rails.

require 'RMagick'

image = Magick::Image.read("input").first.minify

drawable = Magick::Draw.new

drawable.pointsize = 18.0
drawable.gravity = Magick::SouthEastGravity
drawable.font_weight = Magick::BoldWeight

tm = drawable.get_type_metrics(image, "numericalruby.com")

drawable.fill = 'red'
drawable.opacity(0.25)
drawable.roundrectangle(image.columns-tm.width-30,image.rows-tm.height-30,image.columns-10,image.rows-10,7,7)
drawable.draw(image)

drawable.annotate(image,0,0,20,20,"numericalruby.com") {self.fill='black'}

image.write("output")

Some good info also available on the RMagick site

Advertisements