跳轉至內容 跳轉至搜尋

Active Storage 影像分析器

此抽象基底類別適用於影像分析器,從影像區塊中擷取寬度和高度。

如果影像包含 EXIF 資料,指出其角度為 90 或 270 度,則會置換其寬度和高度以方便使用。

範例

ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick.new(blob).metadata
# => { width: 4104, height: 2736 }
命名空間
方法
A
M

類別公共方法

accept?(blob)

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

實例公共方法

metadata()

# 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