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
30 31 32 |
# File 'lib/processors/quick_magick.rb', line 30 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 |
# 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.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
22 23 24 |
# File 'lib/processors/quick_magick.rb', line 22 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
26 27 28 |
# File 'lib/processors/quick_magick.rb', line 26 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 |