Module: RTesseract::Processor::RMagickProcessor
- Defined in:
- lib/processors/rmagick.rb
Overview
Add to rtesseract a image manipulation with RMagick
Class Method Summary collapse
-
.a_name?(name) ⇒ Boolean
Check if is this Processor.
-
.image?(object) ⇒ Boolean
Check if is a RMagick image.
-
.image_to_tif(source, points = {}) ⇒ Object
Convert Image to Tiff.
-
.read_with_processor(path) ⇒ Object
Cast instance of image.
-
.setup ⇒ Object
Setup Processor.
Class Method Details
.a_name?(name) ⇒ Boolean
Check if is this Processor
18 19 20 |
# File 'lib/processors/rmagick.rb', line 18 def self.a_name?(name) %w(rmagick RMagickProcessor).include?(name.to_s) end |
.image?(object) ⇒ Boolean
Check if is a RMagick image
41 42 43 |
# File 'lib/processors/rmagick.rb', line 41 def self.image?(object) object.class == Magick::Image end |
.image_to_tif(source, points = {}) ⇒ Object
Convert Image to Tiff
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/processors/rmagick.rb', line 23 def self.image_to_tif(source, points = {}) tmp_file = Tempfile.new(['', '.tif']) cat = source.is_a?(Pathname) ? read_with_processor(source.to_s) : source cat.crop!(points[:x], points[:y], points[:w], points[:h]) if points.is_a?(Hash) && points.values.compact != [] cat.alpha Magick::DeactivateAlphaChannel cat.write(tmp_file.path.to_s) do # self.depth = 16 self.compression = Magick::NoCompression end tmp_file end |
.read_with_processor(path) ⇒ Object
Cast instance of image
36 37 38 |
# File 'lib/processors/rmagick.rb', line 36 def self.read_with_processor(path) Magick::Image.read(path.to_s).first end |
.setup ⇒ Object
Setup Processor
9 10 11 12 13 14 15 |
# File 'lib/processors/rmagick.rb', line 9 def self.setup require 'rmagick' rescue LoadError # :nocov: require 'RMagick' # :nocov: end |