class ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick

This analyzer relies on the third-party MiniMagick gem. MiniMagick requires the ImageMagick system library.

Public Class Methods

accept?(blob) click to toggle source
# File lib/active_storage/analyzer/image_analyzer/image_magick.rb, line 7
def self.accept?(blob)
  super && ActiveStorage.variant_processor == :mini_magick
end

Private Instance Methods

read_image() { |image| ... } click to toggle source
# File lib/active_storage/analyzer/image_analyzer/image_magick.rb, line 12
def read_image
  begin
    require "mini_magick"
  rescue LoadError
    logger.info "Skipping image analysis because the mini_magick gem isn't installed"
    return {}
  end

  download_blob_to_tempfile do |file|
    image = instrument("mini_magick") do
      MiniMagick::Image.new(file.path)
    end

    if image.valid?
      yield image
    else
      logger.info "Skipping image analysis because ImageMagick doesn't support the file"
      {}
    end
  rescue MiniMagick::Error => error
    logger.error "Skipping image analysis due to an ImageMagick error: #{error.message}"
    {}
  end
end
rotated_image?(image) click to toggle source
# File lib/active_storage/analyzer/image_analyzer/image_magick.rb, line 37
def rotated_image?(image)
  %w[ RightTop LeftBottom TopRight BottomLeft ].include?(image["%[orientation]"])
end