Sha256: 2978a6b476c1735d5046bdf222a21593d36991bd277f0c5f202c005b31e8fe23
Contents?: true
Size: 872 Bytes
Versions: 5
Compression:
Stored size: 872 Bytes
Contents
# encoding: UTF-8 # Add to rtesseract a image manipulation with QuickMagick module QuickMagickProcessor def self.setup require 'quick_magick' end def self.a_name?(name) %w(quick_magick QuickMagickProcessor).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.compress = 'None' cat.format = 'tif' cat.crop("#{w}x#{h}+#{x}+#{y}") if need_crop?( x, y, w, h) cat.write tmp_file.path.to_s tmp_file end def self.need_crop?(x = nil, y = nil, w = nil, h = nil) x.to_f + y.to_f + w.to_f + h.to_f > 0 end def self.read_with_processor(path) QuickMagick::Image.read(path.to_s).first end def self.image?(object) object.class == QuickMagick::Image end end
Version data entries
5 entries across 5 versions & 1 rubygems