Sha256: 80cf7eca4f0af1c2112e74a25bd0bfc2a67a245cdd29ebdf0f15b33f85b6a3a3

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require "image_processing"

module ActiveStorage
  module Transformers
    class ImageProcessingTransformer < Transformer
      private
        def process(file, format:)
          processor.
            source(file).
            loader(page: 0).
            convert(format).
            apply(operations).
            call
        end

        def processor
          ImageProcessing.const_get(ActiveStorage.variant_processor.to_s.camelize)
        end

        def operations
          transformations.each_with_object([]) do |(name, argument), list|
            if name.to_s == "combine_options"
              ActiveSupport::Deprecation.warn <<~WARNING
                Active Storage's ImageProcessing transformer doesn't support :combine_options,
                as it always generates a single ImageMagick command. Passing :combine_options will
                not be supported in Rails 6.1.
              WARNING

              list.concat argument.keep_if { |key, value| value.present? }.to_a
            elsif argument.present?
              list << [ name, argument ]
            end
          end
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activestorage-6.0.0.beta3 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-6.0.0.beta2 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-6.0.0.beta1 lib/active_storage/transformers/image_processing_transformer.rb