mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-15 13:45:25 +08:00
24 lines
681 B
Ruby
24 lines
681 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ActiveStorage
|
|
class Analyzer::CustomImageAnalyzer < Analyzer::ImageAnalyzer
|
|
JPEG_MIME_TYPES = ['image/jpeg', 'image/pjpeg'].freeze
|
|
|
|
def self.accept?(blob)
|
|
blob.content_type.in?(JPEG_MIME_TYPES) && blob.attachments.take.record_type == 'Asset'
|
|
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
|