Class: Dragonfly::ImageMagick::Processors::Thumb

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/image_magick/processors/thumb.rb

Constant Summary collapse

GRAVITIES =
{
  'nw' => 'NorthWest',
  'n'  => 'North',
  'ne' => 'NorthEast',
  'w'  => 'West',
  'c'  => 'Center',
  'e'  => 'East',
  'sw' => 'SouthWest',
  's'  => 'South',
  'se' => 'SouthEast'
}
RESIZE_GEOMETRY =

Geometry string patterns

/\A\d*x\d*[><%^!]?\z|\A\d+@\z/
CROPPED_RESIZE_GEOMETRY =

e.g. '20x50#ne'

/\A(\d+)x(\d+)#(\w{1,2})?\z/
CROP_GEOMETRY =

e.g. '30x30+10+10'

/\A(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?\z/

Instance Method Summary collapse

Instance Method Details

#call(content, geometry, opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dragonfly/image_magick/processors/thumb.rb', line 28

def call(content, geometry, opts={})
  args = case geometry
  when RESIZE_GEOMETRY
    resize_args(geometry)
  when CROPPED_RESIZE_GEOMETRY
    resize_and_crop_args($1, $2, $3)
  when CROP_GEOMETRY
    crop_args(
      'width' => $1,
      'height' => $2,
      'x' => $3,
      'y' => $4,
      'gravity' => $5
    )
  else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
  end
  content.process!(:convert, args, opts)
end

#update_url(url_attributes, geometry, opts = {}) ⇒ Object



23
24
25
26
# File 'lib/dragonfly/image_magick/processors/thumb.rb', line 23

def update_url(url_attributes, geometry, opts={})
  format = opts['format']
  url_attributes.ext = format if format
end