Class: Miso::Processor::CoreImage
- Inherits:
-
Miso::Processor
- Object
- Miso::Processor
- Miso::Processor::CoreImage
- Defined in:
- lib/miso/processor/core_image.rb
Instance Attribute Summary
Attributes inherited from Miso::Processor
Class Method Summary collapse
Instance Method Summary collapse
- #crop(width, height) ⇒ Object
- #dimensions ⇒ Object
- #fit(width, height) ⇒ Object
-
#initialize(input_file) ⇒ CoreImage
constructor
A new instance of CoreImage.
- #write(output_file) ⇒ Object
Methods inherited from Miso::Processor
Constructor Details
#initialize(input_file) ⇒ CoreImage
Returns a new instance of CoreImage.
9 10 11 12 13 |
# File 'lib/miso/processor/core_image.rb', line 9 def initialize(input_file) super require 'osx/cocoa' reset! end |
Class Method Details
.available? ⇒ Boolean
5 6 7 |
# File 'lib/miso/processor/core_image.rb', line 5 def self.available? $:.any? { |path| File.exist? File.join(path, 'osx/cocoa.rb') } end |
Instance Method Details
#crop(width, height) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/miso/processor/core_image.rb', line 19 def crop(width, height) scale_width, scale_height = scale(width, height) multiplier = scale_width > scale_height ? scale_width : scale_height transform(multiplier) # find the center and calculate the new bottom right from there x = ((buffer_width.to_f - width.to_f) / 2).round.abs y = ((buffer_height.to_f - height.to_f) / 2).round.abs _crop(x, y, width, height) end |
#dimensions ⇒ Object
15 16 17 |
# File 'lib/miso/processor/core_image.rb', line 15 def dimensions @dimensions ||= image.extent.size.to_a end |
#fit(width, height) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/miso/processor/core_image.rb', line 30 def fit(width, height) scale_width, scale_height = scale(width, height) multiplier = scale_width < scale_height ? scale_width : scale_height new_width = (self.width * multiplier).round new_height = (self.height * multiplier).round transform(multiplier) _crop(0, 0, new_width, new_height) end |
#write(output_file) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/miso/processor/core_image.rb', line 40 def write(output_file) bitmap = OSX::NSBitmapImageRep.alloc.initWithCIImage(@buffer) blob = bitmap.representationUsingType_properties(detect_file_type(output_file), nil) blob.writeToFile_atomically(output_file, false) reset! end |