Module: BaiduOcr::EncodeImage

Defined in:
lib/baidu_ocr/encode_image.rb

Class Method Summary collapse

Class Method Details

.encode(image) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/baidu_ocr/encode_image.rb', line 8

def encode(image)
  begin
    puts "loading file from #{image}"
    stream = open(image, 'rb').read
  rescue Errno::ENOENT => e
    raise NotFound, "#{e.message}"
  end
  # ruby的Base64.encode64 有换行,好坑,无法满足要求
  Base64.strict_encode64 stream
end