Module: MemeMe::Meme
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
Instance Method Summary collapse
- #bottom_phrase ⇒ Object
- #bottom_phrase=(phrase) ⇒ Object
- #calculate_pointsize(text, pointsize) ⇒ Object
- #generate(path) ⇒ Object
- #meme_text(text, c, config = {}) ⇒ Object
- #name ⇒ Object
- #top_phrase ⇒ Object
- #top_phrase=(phrase) ⇒ Object
- #write_bottom_phrase(img) ⇒ Object
- #write_top_phrase(img) ⇒ Object
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
6 7 8 |
# File 'lib/mememe/meme.rb', line 6 def image @image end |
Instance Method Details
#bottom_phrase ⇒ Object
20 21 22 |
# File 'lib/mememe/meme.rb', line 20 def bottom_phrase @bottom_phrase || "" end |
#bottom_phrase=(phrase) ⇒ Object
24 25 26 |
# File 'lib/mememe/meme.rb', line 24 def bottom_phrase=(phrase) @bottom_phrase = phrase end |
#calculate_pointsize(text, pointsize) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/mememe/meme.rb', line 69 def calculate_pointsize text, pointsize if text.size > 20 pointsize = pointsize - (text.size - 20) * 1.25 pointsize = 28 if pointsize < 28 pointsize.to_s else pointsize.to_s end end |
#generate(path) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/mememe/meme.rb', line 28 def generate(path) raise ArgumentError, "MemeMe::Meme.generate requires a valid image path" unless @image && File.exists?(image) img = MiniMagick::Image.open(image) write_top_phrase img write_bottom_phrase img img.write(File.join(path, "#{name}#{File.extname(image)}")) end |
#meme_text(text, c, config = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mememe/meme.rb', line 48 def meme_text(text, c, config = {}) settings = { font: MemeMe.fonts[:impact], position: 'North', pointsize: 50, stroke_color: '#000', stroke_width: 2, color: '#FFF' }.merge! config settings[:pointsize] = calculate_pointsize text, settings[:pointsize] c.gravity settings[:position] c.font settings[:font] c.pointsize settings[:pointsize] c.stroke settings[:stroke_color] c.strokewidth settings[:stroke_width].to_s c.fill settings[:color] c.draw "text 0,0 '#{text.upcase}'" end |
#name ⇒ Object
8 9 10 |
# File 'lib/mememe/meme.rb', line 8 def name @name || "meme" end |
#top_phrase ⇒ Object
12 13 14 |
# File 'lib/mememe/meme.rb', line 12 def top_phrase @top_phrase || "" end |
#top_phrase=(phrase) ⇒ Object
16 17 18 |
# File 'lib/mememe/meme.rb', line 16 def top_phrase=(phrase) @top_phrase = phrase end |
#write_bottom_phrase(img) ⇒ Object
42 43 44 45 46 |
# File 'lib/mememe/meme.rb', line 42 def write_bottom_phrase(img) img. do |c| meme_text bottom_phrase, c, { position: 'South' } end end |
#write_top_phrase(img) ⇒ Object
36 37 38 39 40 |
# File 'lib/mememe/meme.rb', line 36 def write_top_phrase(img) img. do |c| meme_text top_phrase, c end end |