Module: StraightOutta

Defined in:
lib/straight_outta.rb,
lib/straight_outta/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.somewhere(location, file_path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/straight_outta.rb', line 5

def self.somewhere(location, file_path)
  location = location.upcase

  spec = Gem::Specification.find_by_name('straight_outta')
  resource_path = "#{spec.gem_dir}/resources"

  background = Magick::Image.read("#{resource_path}/images/bg-black4.jpg").first
  frame = Magick::Image.read("#{resource_path}/images/logo-frame-2x.png").first
  grime = Magick::Image.read("#{resource_path}/images/pattern-grime.jpg").first

  crop_x = (background.columns / 2) - (frame.columns / 2)
  crop_y = (background.rows / 2) - (frame.rows / 2)

  # Crop background to the frame
  background.crop!(crop_x, crop_y, frame.columns, frame.rows)

  # Composite background and frame
  result = background.composite(frame, 0, 0, Magick::OverCompositeOp)

  # User-specified location text
  gc = Magick::Draw.new
  gc.gravity = Magick::CenterGravity
  gc.font = "#{resource_path}/fonts/champion-htf-featherweight.ttf"
  gc.font_weight = Magick::NormalWeight
  pointsize = 250
  gc.pointsize = pointsize

  # Calculate pointsize down if text width is wider than the frame
  metrics = gc.get_type_metrics(location)
  while metrics[:width] > result.columns - 20
    pointsize = pointsize - 1
    gc.pointsize = pointsize
    metrics = gc.get_type_metrics(location)
  end

  gc.tile = grime
  gc_width = 0
  gc_height = 0
  gc_pos_x = 0
  gc_pos_y = 318
  gc.annotate(result, gc_width, gc_height, gc_pos_x, gc_pos_y, location)

  result.format = 'png'
  result.write(file_path)
end