Sha256: 82d32e880f8495dde8e9e83be0db249338342bfaf089ce4a049a6ac05131978d

Contents?: true

Size: 1.12 KB

Versions: 39

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "mini_magick"

module ActiveStorage
  module Transformers
    class MiniMagickTransformer < Transformer
      private
        def process(file, format:)
          image = MiniMagick::Image.new(file.path, file)

          transformations.each do |name, argument_or_subtransformations|
            image.mogrify do |command|
              if name.to_s == "combine_options"
                argument_or_subtransformations.each do |subtransformation_name, subtransformation_argument|
                  pass_transform_argument(command, subtransformation_name, subtransformation_argument)
                end
              else
                pass_transform_argument(command, name, argument_or_subtransformations)
              end
            end
          end

          image.format(format) if format

          image.tempfile.tap(&:open)
        end

        def pass_transform_argument(command, method, argument)
          if argument == true
            command.public_send(method)
          elsif argument.present?
            command.public_send(method, argument)
          end
        end
    end
  end
end

Version data entries

39 entries across 39 versions & 4 rubygems

Version Path
activestorage-6.0.3 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.3.rc1 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.2.2 lib/active_storage/transformers/mini_magick_transformer.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/activestorage-6.0.2.1/lib/active_storage/transformers/mini_magick_transformer.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/activestorage-6.0.2.1/lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.2.1 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.2 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.2.rc2 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.2.rc1 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.1 lib/active_storage/transformers/mini_magick_transformer.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activestorage-6.0.0/lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.1.rc1 lib/active_storage/transformers/mini_magick_transformer.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activestorage-6.0.0/lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0.rc2 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0.rc1 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0.beta3 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0.beta2 lib/active_storage/transformers/mini_magick_transformer.rb
activestorage-6.0.0.beta1 lib/active_storage/transformers/mini_magick_transformer.rb