Module: RMagickProcessor

Defined in:
lib/processors/rmagick.rb

Overview

Add to rtesseract a image manipulation with RMagick

Class Method Summary collapse

Class Method Details

.a_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/processors/rmagick.rb', line 8

def self.a_name?(name)
  %w(rmagick RMagickProcessor).include?(name.to_s)
end

.image?(object) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/processors/rmagick.rb', line 24

def self.image?(object)
  object.class == Magick::Image
end

.image_to_tif(source, x = nil, y = nil, w = nil, h = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/processors/rmagick.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.crop!(x, y, w, h) unless [x, y, w, h].compact == []
  cat.write(tmp_file.path.to_s) { self.compression = Magick::NoCompression }
  tmp_file
end

.read_with_processor(path) ⇒ Object



20
21
22
# File 'lib/processors/rmagick.rb', line 20

def self.read_with_processor(path)
  Magick::Image.read(path.to_s).first
end

.setupObject



4
5
6
# File 'lib/processors/rmagick.rb', line 4

def self.setup
  require 'RMagick'
end