Sha256: 49b07bbabece07c9882e017c198215052555f3b2e2df33210ba1cbc72b6f885c

Contents?: true

Size: 744 Bytes

Versions: 5

Compression:

Stored size: 744 Bytes

Contents

require 'rmagick'
require 'mittsu/extras/image'

module Mittsu
  class ImageLoader
    attr_accessor :manager

    def initialize(manager = DefaultLoadingManager)
      @manager = manager
    end

    def load(url, flip: false, flop: false)
      chache_url = "#{url}?flip=#{flip}&flop=#{flop}"
      cached = Cache.get(url)
      return cached unless cached.nil?

      rm_image = Magick::Image.read(url).first
      rm_image = rm_image.flip if flip
      rm_image = rm_image.flop if flop
      rgba_data = rm_image.to_blob { |i|
        i.format = "RGBA"
        i.depth = 8
      }

      image = Image.new(rm_image.columns, rm_image.rows, rgba_data)

      Cache.add(url, image)
      @manager.item_start(url)
      image
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mittsu-0.1.4 lib/mittsu/loaders/image_loader.rb
mittsu-0.1.3 lib/mittsu/loaders/image_loader.rb
mittsu-0.1.2 lib/mittsu/loaders/image_loader.rb
mittsu-0.1.1 lib/mittsu/loaders/image_loader.rb
mittsu-0.1.0 lib/mittsu/loaders/image_loader.rb