Sha256: 25f73c9286478123170c3e994725b83836c915eda8804ccbd3b4c66ef3d487f1

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

begin
  require "image_processing"
rescue LoadError
  raise LoadError, <<~ERROR.squish
    Generating image variants require the image_processing gem.
    Please add `gem 'image_processing', '~> 1.2'` to your Gemfile.
  ERROR
end

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"
              raise ArgumentError, <<~ERROR.squish
                Active Storage's ImageProcessing transformer doesn't support :combine_options,
                as it always generates a single command.
              ERROR
            end

            if argument.present?
              list << [ name, argument ]
            end
          end
        end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activestorage-7.0.2.2 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.2.1 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.2 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.1 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0.rc3 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0.rc2 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0.rc1 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0.alpha2 lib/active_storage/transformers/image_processing_transformer.rb
activestorage-7.0.0.alpha1 lib/active_storage/transformers/image_processing_transformer.rb