Class: Quirc::ImageProcessor::MiniMagick
- Inherits:
-
Quirc::ImageProcessor
- Object
- Quirc::ImageProcessor
- Quirc::ImageProcessor::MiniMagick
- Defined in:
- lib/quirc/image_processor/mini_magick.rb
Instance Attribute Summary
Attributes inherited from Quirc::ImageProcessor
Instance Method Summary collapse
Methods inherited from Quirc::ImageProcessor
Constructor Details
This class inherits a constructor from Quirc::ImageProcessor
Instance Method Details
#to_grayscale(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/quirc/image_processor/mini_magick.rb', line 5 def to_grayscale(*args) read_image do |image| with_tempfile("-grayscale-8bit.tiff") do |tempfile| = args.last.is_a?(Hash) ? args.pop : {} width, height = args width ||= .delete(:width) || image.width height ||= .delete(:height) || image.height pipeline = ImageProcessing::MiniMagick.source(image) if width != image.width || height != image.height pipeline = pipeline.resize_to_fit(width, height, **) end pipeline = pipeline.depth(8) pipeline = pipeline.colorspace("Gray") pipeline = pipeline.alpha("remove") pipeline = pipeline.convert("tiff") pipeline.call(destination: tempfile.path) processed = ::MiniMagick::Image.new(tempfile.path) tempfile.rewind yield tempfile.read, processed.width, processed.height end end end |