Skip to Content Skip to Search
v7.1.0
class ActiveStorage::ImageAnalyzer < ActiveStorage::Analyzer

Active Storage Image Analyzer

This is an abstract base class for image analyzers, which extract width and height from an image blob.

If the image contains EXIF data indicating its angle is 90 or 270 degrees, its width and height are swapped for convenience.

Example:

ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick.new(blob).metadata
# => { width: 4104, height: 2736 }
Methods
A
M

Public class methods

accept?(blob)

Permalink
Source code GitHub
# File activestorage/lib/active_storage/analyzer/image_analyzer.rb, line 15
def self.accept?(blob)
  blob.image?
end

Public instance methods

metadata()

Permalink
Source code GitHub
# File activestorage/lib/active_storage/analyzer/image_analyzer.rb, line 19
def metadata
  read_image do |image|
    if rotated_image?(image)
      { width: image.height, height: image.width }
    else
      { width: image.width, height: image.height }
    end
  end
end
Namespace
Definition files