Class: Mittsu::ImageLoader
- Inherits:
-
Object
- Object
- Mittsu::ImageLoader
- Defined in:
- lib/mittsu/loaders/image_loader.rb
Instance Attribute Summary collapse
-
#manager ⇒ Object
Returns the value of attribute manager.
Instance Method Summary collapse
-
#initialize(manager = DefaultLoadingManager) ⇒ ImageLoader
constructor
A new instance of ImageLoader.
- #load(url, flip: false, flop: false) ⇒ Object
Constructor Details
#initialize(manager = DefaultLoadingManager) ⇒ ImageLoader
Returns a new instance of ImageLoader.
13 14 15 |
# File 'lib/mittsu/loaders/image_loader.rb', line 13 def initialize(manager = DefaultLoadingManager) @manager = manager end |
Instance Attribute Details
#manager ⇒ Object
Returns the value of attribute manager.
11 12 13 |
# File 'lib/mittsu/loaders/image_loader.rb', line 11 def manager @manager end |
Instance Method Details
#load(url, flip: false, flop: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mittsu/loaders/image_loader.rb', line 17 def load(url, flip: false, flop: false) chache_url = "#{url}?flip=#{flip}&flop=#{flop}" cached = Cache.get(chache_url) return cached unless cached.nil? png_image = ChunkyPNG::Image.from_file(url) png_image.flip_horizontally! if flip png_image.flip_vertically! if flop rgba_data = png_image.to_rgba_stream image = Image.new(png_image.width, png_image.height, rgba_data) Cache.add(url, image) @manager.item_start(url) image end |