Sha256: 2fb6423b972db091c6a20442e0836e707ac395c8d96b8a6b8861d5281261af35

Contents?: true

Size: 727 Bytes

Versions: 7

Compression:

Stored size: 727 Bytes

Contents

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

  def self.a_name?(name)
    %w(rmagick RMagickProcessor).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.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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

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