scinote-web/lib/paperclip/image_quality_calculate.rb
aignatov-bio 8d7cc57da1
Add zoom to image annotation and check jpeg file quality before save [SCI-3300] (#1654)
* Add zoom to image annotation and check jpeg file quality before save
* Move compression to front end
* Move quality extractor to paperclip processor
2019-04-15 09:49:44 +02:00

21 lines
704 B
Ruby

# frozen_string_literal: true
module Paperclip
class ImageQualityCalculate < Processor
def initialize(file, options = {}, attachment = nil)
super
end
def make
if @file && (['image/jpeg', 'image/pjpeg'].include? @file.content_type)
quality = Paperclip::Processor.new(@file).identify(" -format '%Q' #{@file.path}")
@attachment.instance.file_image_quality = quality.to_i
# Asset will be save after all processors finished
end
# We need again open file after read quality
File.new(File.expand_path(@file.path))
rescue StandardError => e
raise Paperclip::Error, "There was an error processing the image - #{e}"
end
end
end