Skip to content
Squeegy edited this page Sep 12, 2010 · 9 revisions

text(string_to_write, options = {})

Draw text on the image. Customize size, position, color, dropshadow, and font.

  • string_to_write
    This required argument is the actual string that gets written to the image.

Use the following keys in the options hash:

  • :alignment
    A symbol that tells Fleximage where to put the text. Can be any of the following: :center, :top, :top_right, :right, :bottom_right, :bottom, :bottom_left, :left, :top_left.
  • :offset
    The X and Y distance, in "123x456" format, away from the :alignment anchor. This represents the left edge of the baseline of your text. If the anchor is in the top left, then X and Y move it down and to the right. If in the bottom right, then X and Y and move left and up.
  • :antialias
    By default, the drawn text is antialiased. If you are rendering a small font and do not want antialiasing at all, pass false to this key.
  • :color
    The color of the drawn text. Like "red" or color(255, 0, 0).
  • :font_size
    An integer for the pixel size of the font.
  • :font
    The path to a font file to render your text with. This is relative to RAILS_ROOT
  • :rotate
    You can rotate this text by this many degrees clockwise.
  • :shadow
    This option add a black dropshadow to your text. Pass in a hash like {:blur => 1, :opacity => 1.0}.

Example

@photo.operate do |image|
  image.text('I like Cheese',
    :alignment => :bottom_left,
    :position => '10x10',
    :antialias => true,
    :color => 'blue',
    :font_size => 24,
    :font => 'path/to/myfont.ttf',
    :rotate => 15,
    :shadow => {
      :blur => 3,
      :opacity => 0.5,
    }
  )
end

Back to Operators

Clone this wiki locally