Sha256: 96351445c6fd9a83eaa8772cb988ed913f47f6b07b7499c89a67c8acdb67c5be
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
# encoding: UTF-8 class RTesseract # Class to read an image from specified areas class Mixed attr_reader :areas def initialize(src = '', options = {}) @source = Pathname.new src @options = options @value = '' @areas = options.delete(:areas) || [] yield self if block_given? end def area(x, y, width, height) @value = '' @areas << { x: x, y: y, width: width, height: height } end def clear_areas @areas = [] end # Convert parts of image to string def convert @value = [] @areas.each_with_object(RTesseract.new(@source.to_s, @options.dup)) do |area, image| image.crop!(area[:x], area[:y], area[:width], area[:height]) @value << image.to_s end rescue => error raise RTesseract::ConversionError.new(error), error, caller end # Output value def to_s return @value if @value != '' if @source.file? convert @value.join else fail RTesseract::ImageNotSelectedError.new(@source) end end # Remove spaces and break-lines def to_s_without_spaces to_s.gsub(' ', '').gsub("\n", '').gsub("\r", '') end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rtesseract-1.3.3 | lib/rtesseract/mixed.rb |
rtesseract-1.3.2 | lib/rtesseract/mixed.rb |
rtesseract-1.3.1 | lib/rtesseract/mixed.rb |