Module: Shrine::Plugins::Thumbhash::ImageLoader::MiniMagick
- Defined in:
- lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb
Overview
:nodoc:
Class Method Summary collapse
- .call(io) ⇒ Object
- .load_image(io) ⇒ Object
- .repack_pixels_to_flattened_rgba_array(image) ⇒ Object
- .resize_image(image) ⇒ Object
Class Method Details
.call(io) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb', line 11 def self.call(io) image = load_image(io) image = resize_image(image) Thumbhash::Image.new( image.width, image.height, repack_pixels_to_flattened_rgba_array(image) ) end |
.load_image(io) ⇒ Object
21 22 23 |
# File 'lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb', line 21 def self.load_image(io) ::MiniMagick::Image.read(io) end |
.repack_pixels_to_flattened_rgba_array(image) ⇒ Object
31 32 33 |
# File 'lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb', line 31 def self.repack_pixels_to_flattened_rgba_array(image) image.get_pixels("RGBA").flatten end |
.resize_image(image) ⇒ Object
25 26 27 28 29 |
# File 'lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb', line 25 def self.resize_image(image) return image if image.width <= 100 && image.height <= 100 image.resize("100x100") end |