Sha256: 79979f166d77ce8250b83b582d3dbd988d18b05b3e29f413b20db918b088c159

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module Gif2lgtm
  module Main
    module_function
    LOOP_COUNT = 0

    def start(img_path)
      gif = compsite!(img_path)
      create!(gif, img_path)
    end

    def compsite!(img_path)
      gif                = Magick::ImageList.new
      images             = Magick::ImageList.new(img_path)

      dir_path           = caller[0][/^(.+?):\d+?:in.*/, 1].split('/')
      dir_path.pop(3)
      original_size_lgtm = Magick::ImageList.new(dir_path.join('/') + '/images/lgtm.png')
      lgtm               = original_size_lgtm.resize_to_fit(images.first.columns, images.first.rows)

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

      gif
    end

    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 <<~MESSAGE
        =======================================================
        Lgtm created. path: #{result_path}
        =======================================================

      MESSAGE
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gif2lgtm-1.0.5 lib/gif2lgtm/main.rb