edge badge

Extracts width and height in pixels from an image blob.

Example:

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

This analyzer relies on the third-party MiniMagick gem. MiniMagick requires the ImageMagick system library. These libraries are not provided by Rails; you must install them yourself to use this analyzer.

Methods
A
M
Class Public methods
accept?(blob)
# File activestorage/lib/active_storage/analyzer/image_analyzer.rb, line 14
def self.accept?(blob)
  blob.image?
end
Instance Public methods
metadata()
# File activestorage/lib/active_storage/analyzer/image_analyzer.rb, line 18
def metadata
  read_image do |image|
    { width: image.width, height: image.height }
  end
rescue LoadError
  logger.info "Skipping image analysis because the mini_magick gem isn't installed"
  {}
end