Class: LeMeme::Meme
- Inherits:
-
Object
- Object
- LeMeme::Meme
- Defined in:
- lib/le_meme/meme.rb
Overview
A single meme object
Instance Method Summary collapse
-
#initialize(path, top: nil, bottom: nil, watermark: nil) ⇒ Meme
constructor
A new meme object.
-
#to_blob ⇒ String
Get a binary string representing the meme.
-
#to_file(path = nil) ⇒ File
Outputs the meme to the file system.
Constructor Details
#initialize(path, top: nil, bottom: nil, watermark: nil) ⇒ Meme
Returns A new meme object.
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.(path) @top = top.to_s.upcase @bottom = bottom.to_s.upcase @watermark = watermark @canvas = Magick::ImageList.new(@path) end |
Instance Method Details
#to_blob ⇒ String
Get a binary string representing the meme
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
22 23 24 25 26 27 28 29 30 |
# File 'lib/le_meme/meme.rb', line 22 def to_file(path = nil) path = File.(path.nil? ? "#{ENV['TMPDIR']}meme-#{Time.now.to_i}.jpg" : path) generate! file = File.new(path, 'w+') @canvas.write(path) file end |