2019-10-08 16:42:55 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ActiveStorage
|
|
|
|
class Analyzer::CustomImageAnalyzer < Analyzer::ImageAnalyzer
|
2019-10-08 17:43:45 +08:00
|
|
|
JPEG_MIME_TYPES = ['image/jpeg', 'image/pjpeg'].freeze
|
|
|
|
|
2019-10-08 16:42:55 +08:00
|
|
|
def self.accept?(blob)
|
2019-10-08 17:43:45 +08:00
|
|
|
blob.content_type.in?(JPEG_MIME_TYPES) && blob.attachments.take.record_type == 'Asset'
|
2019-10-08 16:42:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def metadata
|
|
|
|
read_image do |image|
|
|
|
|
quality = image.identify { |b| b.format('%Q') }.to_i
|
|
|
|
blob.attachments.take.record.update(file_image_quality: quality)
|
|
|
|
|
|
|
|
if rotated_image?(image)
|
|
|
|
{ width: image.height, height: image.width }
|
|
|
|
else
|
|
|
|
{ width: image.width, height: image.height }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|