Class: Dragonfly::ImageMagick::Processor
- Inherits:
-
Object
- Object
- Dragonfly::ImageMagick::Processor
- Includes:
- Configurable, Utils
- Defined in:
- lib/dragonfly/image_magick/processor.rb
Constant Summary
- GRAVITIES =
{ 'nw' => 'NorthWest', 'n' => 'North', 'ne' => 'NorthEast', 'w' => 'West', 'c' => 'Center', 'e' => 'East', 'sw' => 'SouthWest', 's' => 'South', 'se' => 'SouthEast' }
- RESIZE_GEOMETRY =
Geometry string patterns
/^\d*x\d*[><%^!]?$|^\d+@$/
- CROPPED_RESIZE_GEOMETRY =
e.g. '20x50#ne'
/^(\d+)x(\d+)#(\w{1,2})?$/
- CROP_GEOMETRY =
e.g. '30x30+10+10'
/^(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?$/
- THUMB_GEOMETRY =
Regexp.union RESIZE_GEOMETRY, CROPPED_RESIZE_GEOMETRY, CROP_GEOMETRY
Instance Attribute Summary
Attributes included from Loggable
Instance Method Summary (collapse)
- - (Object) auto_orient(temp_object)
- - (Object) convert(temp_object, args = '', format = nil)
- - (Object) crop(temp_object, opts = {})
- - (Object) flip(temp_object)
- - (Object) flop(temp_object)
- - (Object) greyscale(temp_object) (also: #grayscale)
- - (Object) resize(temp_object, geometry)
- - (Object) resize_and_crop(temp_object, opts = {})
- - (Object) rotate(temp_object, amount, opts = {})
- - (Object) strip(temp_object)
- - (Object) thumb(temp_object, geometry)
Methods included from Configurable
Methods included from Loggable
Methods included from Shell
#escape_args, #quote, #raise_shell_command_failed, #run
Instance Method Details
- (Object) auto_orient(temp_object)
30 31 32 |
# File 'lib/dragonfly/image_magick/processor.rb', line 30 def auto_orient(temp_object) convert(temp_object, "-auto-orient") end |
- (Object) convert(temp_object, args = '', format = nil)
108 109 110 |
# File 'lib/dragonfly/image_magick/processor.rb', line 108 def convert(temp_object, args='', format=nil) format ? [super, {:format => format.to_sym}] : super end |
- (Object) crop(temp_object, opts = {})
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dragonfly/image_magick/processor.rb', line 34 def crop(temp_object, opts={}) opts = Dragonfly::Utils.symbolize_keys(opts) width = opts[:width] height = opts[:height] gravity = GRAVITIES[opts[:gravity]] x = "#{opts[:x] || 0}" x = '+' + x unless x[/^[+-]/] y = "#{opts[:y] || 0}" y = '+' + y unless y[/^[+-]/] repage = opts[:repage] == false ? '' : '+repage' resize = opts[:resize] convert(temp_object, "#{"-resize #{resize} " if resize}#{"-gravity #{gravity} " if gravity}-crop #{width}x#{height}#{x}#{y} #{repage}") end |
- (Object) flip(temp_object)
50 51 52 |
# File 'lib/dragonfly/image_magick/processor.rb', line 50 def flip(temp_object) convert(temp_object, "-flip") end |
- (Object) flop(temp_object)
54 55 56 |
# File 'lib/dragonfly/image_magick/processor.rb', line 54 def flop(temp_object) convert(temp_object, "-flop") end |
- (Object) greyscale(temp_object) Also known as: grayscale
58 59 60 |
# File 'lib/dragonfly/image_magick/processor.rb', line 58 def greyscale(temp_object) convert(temp_object, "-colorspace Gray") end |
- (Object) resize(temp_object, geometry)
26 27 28 |
# File 'lib/dragonfly/image_magick/processor.rb', line 26 def resize(temp_object, geometry) convert(temp_object, "-resize #{geometry}") end |
- (Object) resize_and_crop(temp_object, opts = {})
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dragonfly/image_magick/processor.rb', line 63 def resize_and_crop(temp_object, opts={}) opts = Dragonfly::Utils.symbolize_keys(opts) if !opts[:width] && !opts[:height] return temp_object elsif !opts[:width] || !opts[:height] attrs = identify(temp_object) opts[:width] ||= attrs[:width] opts[:height] ||= attrs[:height] end opts[:gravity] ||= 'c' opts[:resize] = "#{opts[:width]}x#{opts[:height]}^^" crop(temp_object, opts) end |
- (Object) rotate(temp_object, amount, opts = {})
80 81 82 83 84 |
# File 'lib/dragonfly/image_magick/processor.rb', line 80 def rotate(temp_object, amount, opts={}) opts = Dragonfly::Utils.symbolize_keys(opts) convert(temp_object, "-rotate #{amount}#{opts[:qualifier]}") end |
- (Object) strip(temp_object)
86 87 88 |
# File 'lib/dragonfly/image_magick/processor.rb', line 86 def strip(temp_object) convert(temp_object, "-strip") end |
- (Object) thumb(temp_object, geometry)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dragonfly/image_magick/processor.rb', line 90 def thumb(temp_object, geometry) case geometry when RESIZE_GEOMETRY resize(temp_object, geometry) when CROPPED_RESIZE_GEOMETRY resize_and_crop(temp_object, 'width' => $1, 'height' => $2, 'gravity' => $3) when CROP_GEOMETRY crop(temp_object, 'width' => $1, 'height' => $2, 'x' => $3, 'y' => $4, 'gravity' => $5 ) else raise ArgumentError, "Didn't recognise the geometry string #{geometry}" end end |