Module: Mindee::Image::ImageCompressor
- Defined in:
- lib/mindee.rb,
lib/mindee/image/image_compressor.rb
Overview
Image compressor module to handle image compression.
Class Method Summary collapse
-
.compress_image(image, quality: 85, max_width: nil, max_height: nil) ⇒ StringIO
Resize and/or compress an SKBitmap.
Class Method Details
.compress_image(image, quality: 85, max_width: nil, max_height: nil) ⇒ StringIO
Resize and/or compress an SKBitmap. This assumes the ratio was provided before hands.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mindee/image/image_compressor.rb', line 14 def self.compress_image(image, quality: 85, max_width: nil, max_height: nil) processed_image = ImageUtils.to_image(image) processed_image.format 'jpg' final_width, final_height = ImageUtils.calculate_new_dimensions( processed_image, max_width: max_width, max_height: max_height ) ImageUtils.resize_image(processed_image, final_width, final_height) if final_width || final_height ImageUtils.compress_image_quality(processed_image, quality) ImageUtils.image_to_stringio(processed_image) end |