Sha256: 32e1e85742a3a2f6637c07e4560d78383ea539c55c79de449c43ed9b4f28315e

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

module Locomotive
  module Dragonfly
    module Processors

      # Do the following steps to get a thumb of an image:
      # 1. resize
      # 2. crop
      # 3. optimize
      #
      # It doesn't try to resize and crop at the same time as the default thumb processor does
      class SmartThumb < ::Dragonfly::ImageMagick::Processors::Thumb

        RESIZE_CROP_GEOMETRY = /\A(\d+)x(\d+)\|(\d+)x(\d+)([+-]\d+)?([+-]\d+)?\z/ # e.g. '3840x5760|1920x320+10+10'

        def args_for_geometry(geometry)
          case geometry
          when RESIZE_CROP_GEOMETRY
            smart_resize_and_crop_args(
              width:        $1,
              height:       $2,
              crop_width:   $3,
              crop_height:  $4,
              x:            $5,
              y:            $6
            )
          else
            super
          end
        end

        private

        def smart_resize_and_crop_args(opts)
          "-resize #{opts[:width]}x#{opts[:height]}^^ -gravity Northwest -crop #{opts[:crop_width]}x#{opts[:crop_height]}#{opts[:x]}#{opts[:y]} +repage"
        end

      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.2.0.alpha1 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.1.1 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.1.0 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.1.0.rc1 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.3 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.2 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.1 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.0 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.0.rc0 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.0.alpha3 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.0.alpha2 lib/locomotive/dragonfly/processors/smart_thumb.rb
locomotivecms-4.0.0.alpha1 lib/locomotive/dragonfly/processors/smart_thumb.rb