Text overlay using RMagick

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: