Sha256: 65c07236f816aa5590587a284db824eb8fd1eb3929cfe39439b3a3f83afaef39

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module ActiveStorage
  # This analyzer relies on the third-party {MiniMagick}[https://github.com/minimagick/minimagick] gem. MiniMagick requires
  # the {ImageMagick}[http://www.imagemagick.org] system library.
  class Analyzer::ImageAnalyzer::ImageMagick < Analyzer::ImageAnalyzer
    def self.accept?(blob)
      super && ActiveStorage.variant_processor == :mini_magick
    end

    private
      def read_image
        download_blob_to_tempfile do |file|
          require "mini_magick"

          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
        end
      rescue LoadError
        logger.info "Skipping image analysis because the mini_magick gem isn't installed"
        {}
      rescue MiniMagick::Error => error
        logger.error "Skipping image analysis due to an ImageMagick error: #{error.message}"
        {}
      end

      def rotated_image?(image)
        %w[ RightTop LeftBottom TopRight BottomLeft ].include?(image["%[orientation]"])
      end
  end
end

Version data entries

18 entries across 16 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/lib/active_storage/analyzer/image_analyzer/image_magick.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/lib/active_storage/analyzer/image_analyzer/image_magick.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/lib/active_storage/analyzer/image_analyzer/image_magick.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.3.1 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.3 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.2.4 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.2.3 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.2.2 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.2.1 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.2 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.1 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0.rc3 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0.rc2 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0.rc1 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0.alpha2 lib/active_storage/analyzer/image_analyzer/image_magick.rb
activestorage-7.0.0.alpha1 lib/active_storage/analyzer/image_analyzer/image_magick.rb