Class: Bagel::Graphic::Intro

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

Constant Summary collapse

FILENAME =
'00-intro.png'
MARGIN_X =
0
MARGIN_Y =
20

Instance Method Summary collapse

Constructor Details

#initialize(title = '', description = '') ⇒ Intro

Returns a new instance of Intro.



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

def initialize(title='', description='')
  @title = title
  @description = description
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
33
# File 'lib/bagel/graphic/intro.rb', line 12

def save
  top = Image.new(1920, 1080) { self.background_color = COLOR_TRANSPARENT }
  draw.font_weight = BoldWeight
  draw.pointsize = 64
  draw.annotate(top, 0, 0, 0, 0, @title.upcase)
  top.trim!

  bottom = Image.new(1920, 1080) { self.background_color = COLOR_TRANSPARENT }
  draw.font_weight = NormalWeight
  draw.pointsize = 48
  draw.annotate(bottom, 0, 0, 0, 0, @description)
  bottom.trim!

  height = top.rows + bottom.rows + MARGIN_Y
  canvas = Image.new(1920, height) { self.background_color = COLOR_TRANSPARENT }
  canvas.composite!(top, NorthWestGravity, MARGIN_X, 0, OverCompositeOp)
  canvas.composite!(bottom, SouthWestGravity, MARGIN_X, 0, OverCompositeOp)
  canvas.trim!
  canvas.write(path)

  path
end