Class: LgtmHD::MemeGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_image_URI, output_image_URI) ⇒ MemeGenerator

TODO make options list for this class TODO pass BLOB data into this class instead of paths



12
13
14
15
16
17
18
# File 'lib/lgtm_hd.rb', line 12

def initialize(input_image_URI, output_image_URI)
  @input_image_URI = input_image_URI
  @output_image_URI = output_image_URI

  @img = MiniMagick::Image.open(@input_image_URI)
  @caption_position = :caption_position_bottom
end

Instance Attribute Details

#input_image_URIObject

Returns the value of attribute input_image_URI.



8
9
10
# File 'lib/lgtm_hd.rb', line 8

def input_image_URI
  @input_image_URI
end

#output_image_URIObject

Returns the value of attribute output_image_URI.



8
9
10
# File 'lib/lgtm_hd.rb', line 8

def output_image_URI
  @output_image_URI
end

Instance Method Details

#draw(caption_text = "LGTM") {|@img| ... } ⇒ MiniMagick::Image

Used to create a new Image object data-copy. Not used to “paint” or that kind of thing.

Parameters:

  • caption_text (String) (defaults to: "LGTM")

    Specify the caption for your LGTM meme

Yields:

  • (@img)

Returns:

  • (MiniMagick::Image)

    The drawn image



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lgtm_hd.rb', line 27

def draw (caption_text = "LGTM")
  if @img.respond_to? (:combine_options) then
    @img.combine_options do |c|
      c.gravity captionPosition()
      c.draw "text 0,0 " << "#{caption_text}"
      c.font captionFont
      c.pointsize captionFontSize
      c.density imageDensity
      c.fill captionColor
      c.resize imageMaxSize().reduce() {|w,h| w << 'x' << h} # syntax: convert -resize $wx$h
    end
    @img.contrast
  end
  yield @img if block_given?
end

#export {|@output_image_URI| ... } ⇒ Object

Yields:



43
44
45
46
# File 'lib/lgtm_hd.rb', line 43

def export
  @img.write(@output_image_URI)
  yield @output_image_URI if block_given?
end