Sha256: fdf7c25d5425d20cec0418793abcd99fc7bf27171e2ddc24bdec78f422aa89e2

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

require 'RMagick'
require 'open-uri'

module Ramesh::ImageUtil
  MESH_URL_BASE ='http://tokyo-ame.jwa.or.jp/mesh/000/'
  BACKGROUND_IMAGE_URL = 'http://tokyo-ame.jwa.or.jp/map/map000.jpg'
  MAP_MASK_URL = 'http://tokyo-ame.jwa.or.jp/map/msk000.png'

  include Magick

  def create_moment_image(gif_name)
    mesh_url = MESH_URL_BASE + gif_name

    @background_image ||= Image.from_blob(open(BACKGROUND_IMAGE_URL).read).shift
    @map_image ||= Image.from_blob(open(MAP_MASK_URL).read).shift

    begin
      image_list = [
                    @background_image,
                    Image.from_blob(open(mesh_url).read).shift,
                    @map_image
                   ]
      moment_image = composite_images(image_list)
      moment_image.write(gif_name)
    rescue OpenURI::HTTPError
    end
  end

  def composite_images(image_list)
    image = image_list.shift
    image_list.each { |layer| image = image.composite(layer, 0, 0, OverCompositeOp) }
    image
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramesh-1.0.0 lib/ramesh/image_util.rb