Class: Bagel::Graphic::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/bagel/graphic/comment.rb

Constant Summary collapse

HEIGHT =
40
PADDING =
10
FILENAME_PREFIX =
'comment-'

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Comment

Returns a new instance of Comment.



8
9
10
# File 'lib/bagel/graphic/comment.rb', line 8

def initialize(text)
  @text = text
end

Instance Method Details

#saveObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bagel/graphic/comment.rb', line 12

def save
  text = Image.new(1920, 1080) { self.background_color = COLOR_WHITE }

  draw = Magick::Draw.new do |d|
    d.font_family = FONT_FAMILY
    d.font_weight = FONT_WEIGHT
    d.pointsize = 24
    d.gravity = CenterGravity
    d.fill = COLOR_BLACK
  end

  draw.annotate(text, 0, 0, 0, 0, @text)
  text.trim!

  canvas = Image.new(text.columns + PADDING * 2, HEIGHT) { self.background_color = COLOR_WHITE }
  canvas.composite!(text, CenterGravity, 0, 0, OverCompositeOp)

  canvas.write(path)

  path
end