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}.
  • :stroke
    To add a stroke to your text, pass in a simple hash here. It should have the keys :width (integer in pixels) and :color (string or color object).

Example

@photo.operate do |image|
  image.text('I like Cheese',
    :alignment => :top_left,
    :offset => '300x150',
    :antialias => true,
    :color => 'pink',
    :font_size => 24,
    :font => 'path/to/myfont.ttf',
    :rotate => -15,
    :shadow => {
      :blur => 1,
      :opacity => 0.5,
    },
    :stroke => {
      :width => 1,
      :color => 'black',
    }
  )
end

Back to Operators

Clone this wiki locally