Module: Gif2lgtm::Main

Defined in:
lib/gif2lgtm/main.rb

Constant Summary collapse

LOOP_COUNT =

infinite loop

0

Class Method Summary collapse

Class Method Details

.compsite(img_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gif2lgtm/main.rb', line 10

def compsite(img_path)
  gif = Magick::ImageList.new
  images = Magick::ImageList.new(img_path)
  orig_size_lgtm = Magick::ImageList.new(File.expand_path('../../images/lgtm.png', __dir__))
  lgtm = orig_size_lgtm.resize_to_fit(images.first.columns, images.first.rows)

  images.each do |image|
    gif.push(
      Magick::Image.from_blob(image.to_blob)[0].composite(
        lgtm,
        Magick::CenterGravity,
        Magick::OverCompositeOp))
  end

  gif
end

.create(gif, img_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gif2lgtm/main.rb', line 27

def create(gif, img_path)
  gif.iterations = LOOP_COUNT
  result_path = "#{File.dirname(img_path)}/lgtm#{SecureRandom.hex(5)}_#{File.basename(img_path)}"

  gif.optimize_layers(Magick::OptimizeLayer).write(result_path)
  puts "    =======================================================\n    Lgtm created. path: \#{result_path}\n    =======================================================\n\n  MESSAGE\nend\n"

.start(img_path) ⇒ Object



6
7
8
# File 'lib/gif2lgtm/main.rb', line 6

def start(img_path)
  create(compsite(img_path), img_path)
end