class IboIpsum::Meme

Attributes

image[R]
name[R]
sentence[R]

Public Class Methods

new(sentence, path = default_path) click to toggle source
# File lib/ibo_ipsum/meme.rb, line 11
def initialize(sentence, path = default_path)
  @sentence = sentence
  @image = Image.read(path).first
  @name = "meme_#{SecureRandom::hex(3)}.jpg"
end

Public Instance Methods

default_path() click to toggle source
# File lib/ibo_ipsum/meme.rb, line 17
def default_path
  File.join(File.dirname(__FILE__), "../../img/ibo_1.jpg")
end
generate() click to toggle source
# File lib/ibo_ipsum/meme.rb, line 25
def generate
  text = Draw.new
  text.annotate(image, 0,0,0,0, prepared_sentence) do
    self.gravity = Magick::SouthGravity
    self.pointsize = 35
    self.font_family = "Helvetica"
    self.font_weight = 900
    self.fill = "#FF1493"
    self.stroke = "#FFF"
    self.stroke_width = 1
  end
  save_and_open!
end
prepared_sentence() click to toggle source
# File lib/ibo_ipsum/meme.rb, line 21
def prepared_sentence
  word_wrap(sentence) + "\n"
end
save_and_open!() click to toggle source
# File lib/ibo_ipsum/meme.rb, line 39
def save_and_open!
  puts "saved: #{name}"
  image.write name
  `open #{name}`
end

Private Instance Methods

word_wrap(text, options = {}) click to toggle source

stolen from rails

# File lib/ibo_ipsum/meme.rb, line 48
def word_wrap(text, options = {})
  line_width = options.fetch(:line_width, 25)
  text.split("\n").collect do |line|
    line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
  end * "\n"
end