Sha256: 4f3e60f8353f202954b0786556af6a86208c8a5bffdb2c93cd6830ad136f476a

Contents?: true

Size: 758 Bytes

Versions: 7

Compression:

Stored size: 758 Bytes

Contents

# encoding: UTF-8
# Add to rtesseract a image manipulation with MiniMagick
module MiniMagickProcessor
  def self.setup
    require 'mini_magick'
  end

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

  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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rtesseract-1.2.5 lib/processors/mini_magick.rb
rtesseract-1.2.4 lib/processors/mini_magick.rb
rtesseract-1.2.3 lib/processors/mini_magick.rb
rtesseract-1.2.2 lib/processors/mini_magick.rb
rtesseract-1.2.1 lib/processors/mini_magick.rb
rtesseract-1.2.0 lib/processors/mini_magick.rb
rtesseract-1.1.0 lib/processors/mini_magick.rb