Simple API wrapper for OCR.Space, An awesome free API for converting images to text. Register here for free api key.
Add this line to your application's Gemfile:
gem'ocr_space'And then execute:
$ bundle
Or install it yourself as:
$ gem install ocr_space
Hosted at rubygems.org
Setting env variables with API key is optional but for command line interface to work you will have to set ENV variable 'ocr_api_key' to your API key. For more details on the command line interface, scroll to the bottom of this page.
$ export ocr_api_key='YOUR API KEY'
require'ocr_space'resource=OcrSpace::Resource.new(apikey: "YOUR API KEY")#By default it picks up ocr_api_key='YOUR API KEY' from your env variablesresult=resource.converturl: "http://bit.ly/2ih9aXt"putsresult=>#[{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}]result=resource.clean_converturl: "http://bit.ly/2ih9aXt"putsresult=>#If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTESresult=resource.convertfile: "/Users/suyesh/Desktop/nicola_tesla.jpg"putsresult#Raw result=>#{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}result=resource.clean_convertfile: "/Users/suyesh/Desktop/nicola_tesla.jpg"putsresult=>#If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTESYou can run ocr_space through shell to get quick result from a image using file path or URL.
$ ocr_space /Users/suyesh/Desktop/nicola_tesla.jpg
=> If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES
You can also pass in Optional attributes
isOverlayRequired:
#[Optional] Default = False Allows you to specify if the image/pdf text overlay is required. Overlay could be #used to show the text over the imagelanguage:
#Czech = ce; Danish = dan; Dutch = dut; English = eng; Finnish = fin; French = fre; German = ger;Hungarian=hun;#Italian = ita; Norwegian = nor; Polish = pol; Portuguese = por; Spanish = spa; Swedish = swe; #ChineseSimplified = chs; Greek = gre; Japanese = jpn; Russian = rus; Turkish = tur; ChineseTraditional = cht; #Korean = kor
