Class: Morandi::ImageProcessor
- Inherits:
-
Object
- Object
- Morandi::ImageProcessor
- Defined in:
- lib/morandi/image_processor.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pb ⇒ Object
readonly
Returns the value of attribute pb.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, user_options, local_options = {}) ⇒ ImageProcessor
constructor
A new instance of ImageProcessor.
- #process! ⇒ Object
- #result ⇒ Object
- #write_to_jpeg(fn, quality = nil) ⇒ Object
- #write_to_png(fn, orientation = :any) ⇒ Object
Constructor Details
#initialize(file, user_options, local_options = {}) ⇒ ImageProcessor
Returns a new instance of ImageProcessor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/morandi/image_processor.rb', line 12 def initialize(file, , ={}) @file = file .keys.grep(/^path/).each { |k| .delete(k) } # Give priority to user_options @options = ( || {}).merge( || {}) @local_options = @scale_to = @options['output.max'] @width, @height = @options['output.width'], @options['output.height'] if @file.is_a?(String) get_pixbuf elsif @file.is_a?(Gdk::Pixbuf) or @file.is_a?(Morandi::ProfiledPixbuf) @pb = @file @scale = 1.0 end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/morandi/image_processor.rb', line 6 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/morandi/image_processor.rb', line 5 def @options end |
#pb ⇒ Object (readonly)
Returns the value of attribute pb.
5 6 7 |
# File 'lib/morandi/image_processor.rb', line 5 def pb @pb end |
Class Method Details
.default_icc_path(path) ⇒ Object
8 9 10 |
# File 'lib/morandi/image_processor.rb', line 8 def self.default_icc_path(path) "#{path}.icc.jpg" end |
Instance Method Details
#process! ⇒ Object
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 |
# File 'lib/morandi/image_processor.rb', line 32 def process! # 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! if @options['output.limit'] && @width && @height @pb = @pb.scale_max([@width, @height].max) end @pb end |
#result ⇒ Object
58 59 60 |
# File 'lib/morandi/image_processor.rb', line 58 def result @pb end |
#write_to_jpeg(fn, quality = nil) ⇒ Object
74 75 76 77 |
# File 'lib/morandi/image_processor.rb', line 74 def write_to_jpeg(fn, quality = nil) quality ||= .fetch('quality', 97) @pb.save(fn, 'jpeg', quality: quality) end |
#write_to_png(fn, orientation = :any) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/morandi/image_processor.rb', line 62 def write_to_png(fn, 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(fn, 'png') end |