Module: QuickMagickProcessor
- Defined in:
- lib/processors/quick_magick.rb
Overview
Add to rtesseract a image manipulation with QuickMagick
Class Method Summary collapse
- .a_name?(name) ⇒ Boolean
- .image?(object) ⇒ Boolean
- .image_to_tif(source, x = nil, y = nil, w = nil, h = nil) ⇒ Object
- .need_crop?(x = nil, y = nil, w = nil, h = nil) ⇒ Boolean
- .read_with_processor(path) ⇒ Object
- .setup ⇒ Object
Class Method Details
.a_name?(name) ⇒ Boolean
8 9 10 |
# File 'lib/processors/quick_magick.rb', line 8 def self.a_name?(name) %w(quick_magick QuickMagickProcessor).include?(name.to_s) end |
.image?(object) ⇒ Boolean
31 32 33 |
# File 'lib/processors/quick_magick.rb', line 31 def self.image?(object) object.class == QuickMagick::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 |
# File 'lib/processors/quick_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.compress = 'None' cat.format = 'tif' cat.alpha = 'off' cat.crop("#{w}x#{h}+#{x}+#{y}") if need_crop?(x, y, w, h) cat.write tmp_file.path.to_s tmp_file end |
.need_crop?(x = nil, y = nil, w = nil, h = nil) ⇒ Boolean
23 24 25 |
# File 'lib/processors/quick_magick.rb', line 23 def self.need_crop?(x = nil, y = nil, w = nil, h = nil) x.to_f + y.to_f + w.to_f + h.to_f > 0 end |
.read_with_processor(path) ⇒ Object
27 28 29 |
# File 'lib/processors/quick_magick.rb', line 27 def self.read_with_processor(path) QuickMagick::Image.read(path.to_s).first end |
.setup ⇒ Object
4 5 6 |
# File 'lib/processors/quick_magick.rb', line 4 def self.setup require 'quick_magick' end |