Monday, August 31, 2009

creating images from unicode text using rmagick

To create images from the unicode text, we can use the "encoding" method for the Draw object.

Example:

require "RMagick"

def show_textimg
bg = Magick::Image.new(120,20){self.background_color = "#9E9E9E"}
text = Magick::Draw.new
text.encoding = "Unicode"
text.text(23,14,"ドの半角⇔全角")
text.draw(bg)
bg.write "#{RAILS_ROOT}/public/images/text.jpg"
end

0 comments: