class ActiveAnalysis::Analyzer::ImageAnalyzer
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:
ActiveAnalysis::Analyzer::ImageAnalyzer::ImageMagick.new(blob).metadata # => { width: 4104, height: 2736 }
Public Class Methods
accept?(blob)
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 15 def self.accept?(blob) blob.image? end
Public Instance Methods
metadata()
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 19 def metadata read_image do |image| if rotated_image?(image) { width: image.height, height: image.width, opaque: opaque?(image), **addons(image) }.compact else { width: image.width, height: image.height, opaque: opaque?(image), **addons(image) }.compact end end end
Private Instance Methods
addons(image)
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 42 def addons(image) ActiveAnalysis.addons.select { |addon| addon.accept?(blob) }.map { |addon_class| addon_class.new(image).metadata }.reduce({}, :merge).compact end
opaque?(image)
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 38 def opaque?(image) raise NotImplementedError end
read_image()
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 30 def read_image raise NotImplementedError end
rotated_image?(image)
click to toggle source
# File lib/active_analysis/analyzer/image_analyzer.rb, line 34 def rotated_image?(image) raise NotImplementedError end