Class: STJ::Meme
- Inherits:
-
Object
- Object
- STJ::Meme
- Defined in:
- lib/stj/meme.rb
Instance Attribute Summary collapse
-
#default_phrase ⇒ Object
readonly
Returns the value of attribute default_phrase.
-
#first_phrase ⇒ Object
readonly
Returns the value of attribute first_phrase.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
Instance Method Summary collapse
- #create(path) ⇒ Object
-
#initialize(first_phrase) ⇒ Meme
constructor
A new instance of Meme.
- #output_file_name ⇒ Object
Constructor Details
Instance Attribute Details
#default_phrase ⇒ Object (readonly)
Returns the value of attribute default_phrase.
6 7 8 |
# File 'lib/stj/meme.rb', line 6 def default_phrase @default_phrase end |
#first_phrase ⇒ Object (readonly)
Returns the value of attribute first_phrase.
6 7 8 |
# File 'lib/stj/meme.rb', line 6 def first_phrase @first_phrase end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
6 7 8 |
# File 'lib/stj/meme.rb', line 6 def image @image end |
Instance Method Details
#create(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stj/meme.rb', line 19 def create(path) point_size = 50 img = MiniMagick::Image.open(image) img. do |c| c.gravity 'South' c.font File.join(STJ::LIB_PATH, 'fonts', 'impact.ttf') c.pointsize '50' c.stroke '#000000' c.draw "text 10,0 '#{default_phrase}'" c.fill("#FFFFFF") c.gravity 'North' if first_phrase.size > 20 point_size -= (first_phrase.size - 20) * 1.25 end point_size = 25 if point_size < 25 c.pointsize point_size.to_s c.stroke '#000000' c.draw "text 10,0 '#{first_phrase}'" c.fill("#FFFFFF") end img.write(File.join(path, output_file_name)) end |
#output_file_name ⇒ Object
14 15 16 17 |
# File 'lib/stj/meme.rb', line 14 def output_file_name name = first_phrase.downcase.gsub(/\s+/, '_').gsub(/\W/, '') "tistj_#{name}.jpg" end |