Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update convert.rb to add in additional options provided by ocr.space #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/ocr_space/convert.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
require 'ocr_space/file_post'
module OcrSpace
module Convert
def convert(apikey: @api_key, language: 'eng', isOverlayRequired: false, file: nil, url: nil)
def convert(apikey: @api_key, language: 'eng', isOverlayRequired: false, file: nil, url: nil, file_type: nil, oCREngine: 1, isTable: false,detectOrientation: false, isCreateSearchablePdf: false,isSearchablePdfHideTextLayer: false, scale: false)

if file
@files = File.new(file)
@data = OcrSpace::FilePost.post('/parse/image',
body: { apikey: apikey,
language: language,
isOverlayRequired: isOverlayRequired,
file_type: file_type,
OCREngine: oCREngine,
isTable: isTable,
detectOrientation: detectOrientation,
isCreateSearchablePdf: isCreateSearchablePdf,
isSearchablePdfHideTextLayer: isSearchablePdfHideTextLayer,
scale: scale,
file: @files })
@data = @data.parsed_response['ParsedResults']
elsif url
@data = HTTParty.post('https://api.ocr.space/parse/image',
body: { apikey: apikey,
language: language,
isOverlayRequired: isOverlayRequired,
file_type: file_type,
OCREngine: oCREngine,
isTable: isTable,
detectOrientation: detectOrientation,
isCreateSearchablePdf: isCreateSearchablePdf,
isSearchablePdfHideTextLayer: isSearchablePdfHideTextLayer,
scale: scale,
url: url })
@data = @data.parsed_response['ParsedResults']
else
Expand All @@ -29,13 +44,21 @@ def clean_convert(apikey: @api_key, language: 'eng', isOverlayRequired: false, f
body: { apikey: apikey,
language: language,
isOverlayRequired: isOverlayRequired,
file_type: file_type,
OCREngine: OCREngine,
detectOrientation: detectOrientation,
scale: scale,
file: @files })
@data = @data.parsed_response['ParsedResults'][0]["ParsedText"].gsub(/\r|\n/, "")
elsif url
@data = HTTParty.post('https://api.ocr.space/parse/image',
body: { apikey: apikey,
language: language,
isOverlayRequired: isOverlayRequired,
file_type: file_type,
OCREngine: OCREngine,
detectOrientation: detectOrientation,
scale: scale,
url: url })
@data = @data.parsed_response['ParsedResults'][0]["ParsedText"].gsub(/\r|\n/, "")
else
Expand Down