Class: MemeCaptain::TextPos

Inherits:
Object
  • Object
show all
Defined in:
lib/meme_captain/text_pos.rb

Overview

Text to put on an image with position and style options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, x, y, width, height, options = {}) ⇒ TextPos

x and y are the coordinates of the top left corner of the text bounding rectangle.

width and height are the width and height of the text bounding rectangle.

x, y, width and height can be in pixels or a float that represents a percentage of the width and height of the image the text is put onto.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/meme_captain/text_pos.rb', line 18

def initialize(text, x, y, width, height, options = {})
  @text = text
  @x = x
  @y = y
  @width = width
  @height = height

  @max_lines = options.delete(:max_lines) || 16
  @min_pointsize = options.delete(:min_pointsize) || 12

  @draw_options = {
      fill: 'white',
      font: 'Impact',
      gravity: Magick::CenterGravity,
      stroke: 'black',
      stroke_width: 8,
  }.merge(options)
end

Instance Attribute Details

#draw_optionsObject

Returns the value of attribute draw_options.



44
45
46
# File 'lib/meme_captain/text_pos.rb', line 44

def draw_options
  @draw_options
end

#heightObject

Returns the value of attribute height.



41
42
43
# File 'lib/meme_captain/text_pos.rb', line 41

def height
  @height
end

#max_linesObject

Returns the value of attribute max_lines.



42
43
44
# File 'lib/meme_captain/text_pos.rb', line 42

def max_lines
  @max_lines
end

#min_pointsizeObject

Returns the value of attribute min_pointsize.



43
44
45
# File 'lib/meme_captain/text_pos.rb', line 43

def min_pointsize
  @min_pointsize
end

#textObject

Returns the value of attribute text.



37
38
39
# File 'lib/meme_captain/text_pos.rb', line 37

def text
  @text
end

#widthObject

Returns the value of attribute width.



40
41
42
# File 'lib/meme_captain/text_pos.rb', line 40

def width
  @width
end

#xObject

Returns the value of attribute x.



38
39
40
# File 'lib/meme_captain/text_pos.rb', line 38

def x
  @x
end

#yObject

Returns the value of attribute y.



39
40
41
# File 'lib/meme_captain/text_pos.rb', line 39

def y
  @y
end