Module: RMagickProcessor
- Defined in:
- lib/processors/rmagick.rb
Overview
Add to rtesseract a image manipulation with RMagick
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
12 13 14 |
# File 'lib/processors/rmagick.rb', line 12 def self.a_name?(name) %w(rmagick RMagickProcessor).include?(name.to_s) end |
.image?(object) ⇒ Boolean
32 33 34 |
# File 'lib/processors/rmagick.rb', line 32 def self.image?(object) object.class == Magick::Image end |
.image_to_tif(source, x = nil, y = nil, w = nil, h = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/processors/rmagick.rb', line 16 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.crop!(x, y, w, h) unless [x, y, w, h].compact == [] cat.alpha Magick::DeactivateAlphaChannel cat.write(tmp_file.path.to_s) { # self.depth = 16 self.compression = Magick::NoCompression } tmp_file end |
.read_with_processor(path) ⇒ Object
28 29 30 |
# File 'lib/processors/rmagick.rb', line 28 def self.read_with_processor(path) Magick::Image.read(path.to_s).first end |
.setup ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/processors/rmagick.rb', line 4 def self.setup require 'rmagick' rescue LoadError # :nocov: require 'RMagick' # :nocov: end |