Class: Dragonfly::ImageMagick::Processors::Thumb
- Includes:
- ParamValidators
- 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/
Constants included from ParamValidators
ParamValidators::IS_NUMBER, ParamValidators::IS_WORD, ParamValidators::IS_WORDS
Instance Method Summary collapse
- #args_for_geometry(geometry) ⇒ Object
- #call(content, geometry, opts = {}) ⇒ Object
- #update_url(url_attributes, geometry, opts = {}) ⇒ Object
Methods included from ParamValidators
is_number, is_word, is_words, validate!, validate_all!, validate_all_keys!
Instance Method Details
#args_for_geometry(geometry) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dragonfly/image_magick/processors/thumb.rb', line 40 def args_for_geometry(geometry) 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 end |
#call(content, geometry, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/dragonfly/image_magick/processors/thumb.rb', line 31 def call(content, geometry, opts = {}) validate!(opts["format"], &is_word) validate!(opts["frame"], &is_number) Commands.convert(content, args_for_geometry(geometry), { "format" => opts["format"], "frame" => opts["frame"], }) end |
#update_url(url_attributes, geometry, opts = {}) ⇒ Object
26 27 28 29 |
# File 'lib/dragonfly/image_magick/processors/thumb.rb', line 26 def update_url(url_attributes, geometry, opts = {}) format = opts["format"] url_attributes.ext = format if format end |