Sha256: 154c5e05c2da269edf74b6ca8c5ad687306c965fe25a63a7ab4a79ab69369c48

Contents?: true

Size: 993 Bytes

Versions: 109

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

require "dragonfly/image_magick/commands"

module Alchemy
  module Dragonfly
    module Processors
      class CropResize
        include ::Dragonfly::ParamValidators

        IS_CROP_ARGUMENT = ->(args_string) {
          args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::CROP_GEOMETRY)
        }

        IS_RESIZE_ARGUMENT = ->(args_string) {
          args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::RESIZE_GEOMETRY)
        }

        def call(content, crop_argument, resize_argument)
          validate!(crop_argument, &IS_CROP_ARGUMENT)
          validate!(resize_argument, &IS_RESIZE_ARGUMENT)
          ::Dragonfly::ImageMagick::Commands.convert(
            content,
            "-crop #{crop_argument} -resize #{resize_argument}"
          )
        end

        def update_url(attrs, _args = "", opts = {})
          format = opts["format"]
          attrs.ext = format if format
        end
      end
    end
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.6 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.2.9 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.4.1 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.4.0 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.5 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.2.8 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.1.13 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.0.16 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.4 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.3 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.2 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.2.7 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.1 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.3.0 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.2.6 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.2.5 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.1.12 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-7.0.15 lib/alchemy/dragonfly/processors/crop_resize.rb
alchemy_cms-6.1.10 lib/alchemy/dragonfly/processors/crop_resize.rb