Class: TxOcr::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/tx_ocr/image.rb

Constant Summary

Constants inherited from Base

Base::HOST

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#encode_parameters, #fixed_paramaters, #full_request_url, #indent_result, #json, #orginal_parameters, #raw_result, #region, #request_object, #request_params, #secret_id, #secret_key, #signature, #string_for_sign, #to_params, #url

Constructor Details

#initialize(file_path, ocr_type = 'GeneralBasicOCR') ⇒ Image

Returns a new instance of Image.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tx_ocr/image.rb', line 5

def initialize(file_path, ocr_type = 'GeneralBasicOCR')
  @file_path = file_path
  @ocr_type = ocr_type

  extname = File.extname(@file_path)
  basename = File.basename(@file_path, extname)
  random_filename = Time.now.to_i.to_s
  new_filename = "#{random_filename}#{extname}"
  # 上传
  TencentCosSdk.put new_filename, file: @file_path

  @remote_image_url = "http://#{TxOcr.config[:bucket]}.cos.#{TxOcr.config[:region]}.myqcloud.com" + TxOcr.config[:parent_path] + "/#{new_filename}"

end

Instance Attribute Details

#remote_image_urlObject (readonly)

Returns the value of attribute remote_image_url.



27
28
29
# File 'lib/tx_ocr/image.rb', line 27

def remote_image_url
  @remote_image_url
end

Instance Method Details

#encoded_image_urlObject



29
30
31
# File 'lib/tx_ocr/image.rb', line 29

def encoded_image_url
  URI.encode(@remote_image_url)
end

#new_filenameObject



20
21
22
23
24
25
# File 'lib/tx_ocr/image.rb', line 20

def new_filename
  extname = File.extname(@file_path)
  basename = File.basename(@file_path, extname)
  random_filename = Time.now.to_i.to_s
  "#{random_filename}#{extname}"
end