<commit_before>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(filename)
    mesh_url = MESH_URL_BASE + filename

    begin
      image_list = [
                    Image.from_blob(open(BACKGROUND_IMAGE_URL).read).shift,
                    Image.from_blob(open(MAP_MASK_URL).read).shift,
                    Image.from_blob(open(mesh_url).read).shift
                   ]
      moment_image = composite_images(image_list)
      moment_image.write(filename)
    rescue OpenURI::HTTPError
    end
  end

  def composite_images(image_list)
    image = image_list.shift

    (1...image_list.length).each { |i| image = image.composite(image_list[i], 0, 0, OverCompositeOp) }

    image
  end
end<commit_msg>Change the order of layers<commit_after>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(filename)
    mesh_url = MESH_URL_BASE + filename

    begin
      image_list = [
                    Image.from_blob(open(BACKGROUND_IMAGE_URL).read).shift,
                    Image.from_blob(open(mesh_url).read).shift,
                    Image.from_blob(open(MAP_MASK_URL).read).shift
                   ]
      moment_image = composite_images(image_list)
      moment_image.write(filename)
    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
{'fraction_non_alphanumeric': 0.113107822410148, 'fraction_numerical': 0.012156448202959831, 'mean_word_length': 2.808853118712274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2098546', 'n_tokens_mistral': 700, 'n_tokens_neox': 653, 'n_words': 93}