Class: LeMeme::Meme

Inherits:
Object
  • Object
show all
Defined in:
lib/le_meme/meme.rb

Overview

A single meme object

Instance Method Summary collapse

Constructor Details

#initialize(path, top: nil, bottom: nil, watermark: nil) ⇒ Meme

Returns A new meme object.

Parameters:

  • path (String, Pathanem)

    Path to an image for the meme background

  • top: (String) (defaults to: nil)

    nil The text on the top of the meme

  • bottom: (String) (defaults to: nil)

    nil The text on the bottom of the meme

  • watermark: (String) (defaults to: nil)

    nil Watermark text



10
11
12
13
14
15
16
# File 'lib/le_meme/meme.rb', line 10

def initialize(path, top: nil, bottom: nil, watermark: nil)
  @path = File.expand_path(path)
  @top = top.to_s.upcase
  @bottom = bottom.to_s.upcase
  @watermark = watermark
  @canvas = Magick::ImageList.new(@path)
end

Instance Method Details

#to_blobString

Get a binary string representing the meme

Returns:

  • (String)


35
36
37
38
39
# File 'lib/le_meme/meme.rb', line 35

def to_blob
  generate!

  @canvas.to_blob
end

#to_file(path = nil) ⇒ File

Outputs the meme to the file system

Parameters:

  • path (String) (defaults to: nil)

    nil Where to save the meme

Returns:

  • (File)

    File object representing the meme



22
23
24
25
26
27
28
29
30
# File 'lib/le_meme/meme.rb', line 22

def to_file(path = nil)
  path = File.expand_path(path.nil? ? "#{ENV['TMPDIR']}meme-#{Time.now.to_i}.jpg" : path)
  generate!

  file = File.new(path, 'w+')
  @canvas.write(path)

  file
end