Class: OCRSDK::Image
- Inherits:
-
AbstractEntity
- Object
- AbstractEntity
- OCRSDK::Image
- Includes:
- Verifiers::Format, Verifiers::Language, Verifiers::Profile
- Defined in:
- lib/ocrsdk/image.rb
Direct Known Subclasses
Constant Summary
Constants included from Verifiers::Profile
Constants included from Verifiers::Format
Verifiers::Format::INPUT_FORMATS, Verifiers::Format::OUTPUT_FORMATS
Constants included from Verifiers::Language
Verifiers::Language::LANGUAGES
Instance Method Summary collapse
- #as_pdf(languages) ⇒ Object
- #as_pdf_sync(languages, out_path = nil, wait_interval = OCRSDK.config.default_poll_time) ⇒ Object
- #as_text(languages) ⇒ Object
- #as_text_sync(languages, wait_interval = OCRSDK.config.default_poll_time) ⇒ Object
-
#initialize(image_path) ⇒ Image
constructor
A new instance of Image.
Methods included from Verifiers::Profile
#profile_to_s, #supported_profile?
Methods included from Verifiers::Format
#format_to_s, #supported_input_format?, #supported_output_format?
Methods included from Verifiers::Language
#language_to_s, #language_to_sym, #languages_to_s, #supported_language?
Constructor Details
#initialize(image_path) ⇒ Image
Returns a new instance of Image.
6 7 8 9 |
# File 'lib/ocrsdk/image.rb', line 6 def initialize(image_path) super() @image_path = image_path end |
Instance Method Details
#as_pdf(languages) ⇒ Object
21 22 23 24 25 |
# File 'lib/ocrsdk/image.rb', line 21 def as_pdf(languages) xml_string = api_process_image @image_path, languages, :pdf_text_and_images, :document_conversion OCRSDK::Promise.from_response xml_string end |
#as_pdf_sync(languages, out_path = nil, wait_interval = OCRSDK.config.default_poll_time) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/ocrsdk/image.rb', line 27 def as_pdf_sync(languages, out_path=nil, wait_interval=OCRSDK.config.default_poll_time) result = as_pdf(languages).wait(wait_interval).result if out_path.nil? result else File.open(out_path, 'wb+') {|f| f.write result } end end |
#as_text(languages) ⇒ Object
11 12 13 14 15 |
# File 'lib/ocrsdk/image.rb', line 11 def as_text(languages) xml_string = api_process_image @image_path, languages, :txt, :text_extraction OCRSDK::Promise.from_response xml_string end |
#as_text_sync(languages, wait_interval = OCRSDK.config.default_poll_time) ⇒ Object
17 18 19 |
# File 'lib/ocrsdk/image.rb', line 17 def as_text_sync(languages, wait_interval=OCRSDK.config.default_poll_time) as_text(languages).wait(wait_interval).result.force_encoding('utf-8') end |