Module: MiniMagickProcessor

Defined in:
lib/processors/mini_magick.rb

Overview

Add to rtesseract a image manipulation with MiniMagick

Class Method Summary collapse

Class Method Details

.a_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.a_name?(name)
  %w(mini_magick MiniMagickProcessor).include?(name.to_s)
end

.image?(object) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/processors/mini_magick.rb', line 25

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

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



12
13
14
15
16
17
18
19
# File 'lib/processors/mini_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.format('tif') { |c| c.compress 'None' }
  cat.crop("#{w}x#{h}+#{x}+#{y}") unless [x, y, w, h].compact == []
  cat.write tmp_file.path.to_s
  tmp_file
end

.read_with_processor(path) ⇒ Object



21
22
23
# File 'lib/processors/mini_magick.rb', line 21

def self.read_with_processor(path)
  MiniMagick::Image.open(path.to_s)
end

.setupObject



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

def self.setup
  require 'mini_magick'
end