module Shrine::Plugins::StoreDimensions

  1. lib/shrine/plugins/store_dimensions.rb

Documentation can be found on shrinerb.com/docs/plugins/store_dimensions

Methods

Public Class

  1. configure

Constants

LOG_SUBSCRIBER = -> (event) do Shrine.logger.info "Image Dimensions (#{event.duration}ms) – #{{ io: event[:io].class, uploader: event[:uploader], }.inspect}" end  

Public Class methods

configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
[show source]
   # File lib/shrine/plugins/store_dimensions.rb
14 def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
15   uploader.opts[:store_dimensions] ||= { analyzer: :fastimage, on_error: :warn, auto_extraction: true }
16   uploader.opts[:store_dimensions].merge!(opts)
17 
18   # resolve error strategy
19   uploader.opts[:store_dimensions][:on_error] =
20     case uploader.opts[:store_dimensions][:on_error]
21     when :fail   then -> (error) { fail error }
22     when :warn   then -> (error) { Shrine.warn "Error occurred when attempting to extract image dimensions: #{error.inspect}" }
23     when :ignore then -> (error) { }
24     else
25       uploader.opts[:store_dimensions][:on_error]
26     end
27 
28   # instrumentation plugin integration
29   uploader.subscribe(:image_dimensions, &log_subscriber) if uploader.respond_to?(:subscribe)
30 end