Module: MiniMagickProcessor
- Defined in:
- lib/processors/mini_magick.rb
Overview
Add to rtesseract a image manipulation with MiniMagick
Class Method Summary collapse
- .a_name?(name) ⇒ Boolean
- .image?(object) ⇒ Boolean
- .image_to_tif(source, x = nil, y = nil, w = nil, h = nil) ⇒ Object
- .read_with_processor(path) ⇒ Object
- .setup ⇒ Object
Class Method Details
.a_name?(name) ⇒ Boolean
8 9 10 |
# File 'lib/processors/mini_magick.rb', line 8 def self.a_name?(name) %w(mini_magick MiniMagickProcessor).include?(name.to_s) end |
.image?(object) ⇒ Boolean
29 30 31 |
# File 'lib/processors/mini_magick.rb', line 29 def self.image?(object) object.class == MiniMagick::Image end |
.image_to_tif(source, x = nil, y = nil, w = nil, h = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/processors/mini_magick.rb', line 12 def self.image_to_tif(source, x = nil, y = nil, w = nil, h = nil) tmp_file = Tempfile.new(['', '.tif']) cat = source.is_a?(Pathname) ? read_with_processor(source.to_s) : source cat.format('tif') do |c| c.compress 'None' c.alpha 'off' end cat.crop("#{w}x#{h}+#{x}+#{y}") unless [x, y, w, h].compact == [] cat.alpha 'off' cat.write tmp_file.path.to_s tmp_file end |
.read_with_processor(path) ⇒ Object
25 26 27 |
# File 'lib/processors/mini_magick.rb', line 25 def self.read_with_processor(path) MiniMagick::Image.open(path.to_s) end |
.setup ⇒ Object
4 5 6 |
# File 'lib/processors/mini_magick.rb', line 4 def self.setup require 'mini_magick' end |