Class: Morandi::ImageProcessor
- Inherits:
-
Object
- Object
- Morandi::ImageProcessor
- Defined in:
- lib/morandi/image_processor.rb
Overview
ImageProcessor transforms an image.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pb ⇒ Object
readonly
Returns the value of attribute pb.
Instance Method Summary collapse
-
#initialize(file, user_options, local_options = {}) ⇒ ImageProcessor
constructor
A new instance of ImageProcessor.
- #process! ⇒ Object
-
#result ⇒ Object
Returns generated pixbuf.
- #write_to_jpeg(write_to, quality = nil) ⇒ Object
- #write_to_png(write_to, orientation = :any) ⇒ Object
Constructor Details
#initialize(file, user_options, local_options = {}) ⇒ ImageProcessor
Returns a new instance of ImageProcessor.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/morandi/image_processor.rb', line 16 def initialize(file, , = {}) @file = file .keys.grep(/^path/).each { |k| .delete(k) } # Give priority to user_options @options = ( || {}).merge( || {}) @local_options = @max_size_px = @options['output.max'] @width = @options['output.width'] @height = @options['output.height'] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/morandi/image_processor.rb', line 14 def @options end |
#pb ⇒ Object (readonly)
Returns the value of attribute pb.
14 15 16 |
# File 'lib/morandi/image_processor.rb', line 14 def pb @pb end |
Instance Method Details
#process! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/morandi/image_processor.rb', line 30 def process! case @file when String get_pixbuf when GdkPixbuf::Pixbuf, Morandi::ProfiledPixbuf @pb = @file @scale = 1.0 end # Apply Red-Eye corrections apply_redeye! # Apply contrast, brightness etc apply_colour_manipulations! # apply rotation apply_rotate! # apply crop apply_crop! # apply filter apply_filters! # add border apply_decorations! @pb = @pb.scale_max([@width, @height].max) if @options['output.limit'] && @width && @height @pb rescue GdkPixbuf::PixbufError::UnknownType => e raise UnknownTypeError, e. rescue GdkPixbuf::PixbufError::CorruptImage => e raise CorruptImageError, e. end |
#result ⇒ Object
Returns generated pixbuf
67 68 69 70 |
# File 'lib/morandi/image_processor.rb', line 67 def result process! unless @pb @pb end |
#write_to_jpeg(write_to, quality = nil) ⇒ Object
84 85 86 87 |
# File 'lib/morandi/image_processor.rb', line 84 def write_to_jpeg(write_to, quality = nil) quality ||= .fetch('quality', '97') @pb.save(write_to, 'jpeg', quality: quality.to_s) end |
#write_to_png(write_to, orientation = :any) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/morandi/image_processor.rb', line 72 def write_to_png(write_to, orientation = :any) pb = @pb case orientation when :landscape pb = @pb.rotate(90) if @pb.width < @pb.height when :portrait pb = @pb.rotate(90) if @pb.width > @pb.height end pb.save(write_to, 'png') end |