Ruby on Rails - Rtesseract not working on Heroku - ruby-on-rails

I am trying to deploy on Heroku RTesseract feature to read text on image.
I add the gem into the Gemfile
gem 'rtesseract'
I implemented the feature into the PagesController#home (sure it is dirty but it is for testing before adding to my real app)
class PagesController < ApplicationController
def home
image = RTesseract.new('https://www.drillster.com/info/img/screenshot-ticket-received.en.png')
#result = image.to_s
end
end
It is working well on http://localhost:3000/. I can see the text printing of the page
When I deploy on Heroku, I have add the following buildpacks :
heroku buildpacks:set heroku/ruby
heroku buildpacks:add https://github.com/pathwaysmedical/heroku-buildpack-tesseract
When I start my application on Heroku, I can see the error :
Tesseract::Error (Cannot open input file:
https://www.drillster.com/info/img/screenshot-ticket-received.en.png)
The error is raising when the code executed the line #result = image.to_s
If someone has already solve this issue, it will be really nice to help me !
Thanks in advance for your help & reading !

So it looks like they added libcurl to get images from URLS in this commit here:
https://github.com/tesseract-ocr/tesseract/commit/286d8275c783062057d09bb8e5e6607a8917abd9
That was in OCT 2019
Looking in the changelog here:
https://github.com/tesseract-ocr/tesseract/blob/master/ChangeLog
We see that version 2018-10-29 - V4.0.0
the version in that buildpack is:
https://github.com/pathwaysmedical/heroku-buildpack-tesseract/blob/master/tesseract-ocr-4.0.tar.gz
So I'm guessing that the buildpack version doesn't support getting the image via URL. I bet when you run it locally you have 4.1 and not the older 4.0?
You could fork that buildpack, get the latest source and compile it with libcurl, or you could try download it to a tempfile and then pass that tempfile location to the library. Though that's not awesome for a variety of reasons and you probably want to delete it when you're done.
If I'm wrong about the version numbers please let me know.
If you install httparty, you could do something like this to test it
url = 'https://www.drillster.com/info/img/screenshot-ticket-received.en.png'
File.open("/tmp/test_file.jpg", "wb") do |f|
f.write HTTParty.get(url).body
end
image = RTesseract.new('/tmp/test_file.jpg')
image.to_s
# "Requested ticket\n\nTo make this test, a user must have a ticket....."

Related

Rails App Assets Not Being Loaded on Development Environment

Every time I spin up my Rails App locally, none of the CSS shows up. The debugger in the browser shows a get request for all of the asset files with fingerprinting, but they all fail since the files can't be found. Here is what one of those requests looks like:
GET http://localhost:3000/assets/announcements.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1
In the Rails Server Console, I get a Rack App Error, as well as a NoMethodError for the undefined method 'Silence'. Here is what one of those errors looks like:
2017-01-08 17:24:49 -0800: Rack app error handling request { GET /assets/normalize.self-cadbbf81015902777c37852b3ea54398335fd421c6c76891c077ec5954211bb4.css }
NoMethodError: undefined method 'silence' for #<Logger:0x007fe1062c1c78
Both Error logs (Browser Console and Localhost Server Console) contain multiple renditions of the same error, all pointing to Assets (*.js, and *.css).
I have searched through countless StackOverflow Posts but to no avail. This also for some reason only affects this one application; all my other Rails applications run fine. Here are my specifications:
Rails Version: 5.0.1
Ruby Version: 2.3.1p112
Things I have tried:
assets:clean, assets:precompile, rm -rf /tmp and /public/assets directpories, all of the previous prepended with the development environment, recloning the repository from github and bundle installing.
I know this is an old question, but stumbled across this while trying to fix the same problem.
I found as well as Ryan Bigg's answer I needed to comment out the following line in development.rb to stop Sprockets from bombing in Rails 5.2.2:
# Suppress logger output for asset requests.
# config.assets.quiet = true
It looks like you're running into this issue: https://github.com/rails/sprockets-rails/issues/376.
Where you've made this configuration change you should be using ActiveSupport::Logger instead. Where you have Logger.new, use ActiveSupport::Logger instead.
check The Sprockets 4 Manifest in rails 5
http://eileencodes.com/posts/the-sprockets-4-manifest/
It might help you.

Error when trying to view uploaded ruby on rails application on Heroku

I'm having problems with trying to view my first Ruby on Rails application on Heroku as a user called LHH has helped me with the first problem which has been about an error uploading but anyway, that has been fixed and now I'm having the problem where I cannot view the application as I am getting the following error.
"We're sorry, but something went wrong. If you are the application owner check the logs for more information"
Error - http://prntscr.com/aepg5c
I opened the log for the deploy that claims it was successful and this is the complete log in this screenshot - http://prntscr.com/aerjnv
I'm not really one to be using ruby on rails as this is my first application that worked and I don't use the Heroku toolkit so what I'm doing is linking it to github via the browser page and telling it where to get the files and the reason why I'm not using the command line is because for some odd reason the Heroku toolkit isn't working with my Windows 10 system.
Open your Gemfile.lock and remove
PLATFORMS
x86-mingw32
then add and try to push on heroku.
PLATFORMS
ruby
for more check here https://devcenter.heroku.com/articles/bundler-windows-gemfile

MiniMagick error. undefined method 'resize'

This error only happens when executed by the Ruby on Rails server.
I've tried bypassing Carrierwave's resize option by implementing my own but it has the same result.
when I run a script from command line (in which I require the 'mini_magick' gem). It all works flawlessly.
the MiniMagick gem seems to be installed correctly and to be honest I'm kinda out of ideas to tackle this problem.
some versions (not sure if usefull or not):
ruby - 1.9.3p545
rails - 4.1.1
mini_magick - 4.0.1
ImageMagick - 6.9.0-0 Q16
Any help is appreciated.
-edit, I'm using windows 8.1
example code:
require 'mini_magick'
filename = 'test.jpg'
image = MiniMagick::Image.open(filename)
image.resize "1000x1000"
image.format "png"
image.write "test.png"
The code above works flawlessly when executed from cmd.
thumb = MiniMagick::Image.open(i.image.path)
thumb.resize "200*200"
code snippet above throws error in RoR when placed in a controller (Create)
alternatively, uncommenting the resize option directly from carrierwave throws the exact same error.
# version :thumb do
# process :resize_to_fill => [200, 200]
# end
Also a little note:
I've disabled minimagicks validations to figure out what causes the error it threw at that time:
Failed to manipulate with MiniMagick, maybe it is not an image? original error: executable not found: "identify"
I hope this clears a few things up.
-edit
I've decided to leave windows as a dev platform and switch to linux as a dev platform. fixed all of my issues (In hindsight my error was probably due to some lacking dependencies on the imagemagick side).
I experienced a similar problem recently with the following environment:
Windows 8.1
Ruby 2.1.5p273
Ruby Dev Kit 2.1.5
Rails 4.2.0.beta4
carrierwave 0.10.0
mini_magick 4.0.1
ImageMagick6.9.0-Q16 installed at C:\ImageMagick-6.9.0-Q16
In the rails console within RubyMine, I would get:
executable not found: "identify"
after keying in just two things:
filename = 'test.jpg'
image = MiniMagick::Image.open(filename)
One of the steps was to add C:\ImageMagick-6.9.0-Q16 to my Windows PATH environment variable. At first, that didn't help. However, after closing and re-opening RubyMine, the problem went away -- I assume because the change to the PATH env var (done with an independent Windows command prompt) didn't affect the RubyMine IDE environment.
executable not found: "identify"
This is an error message from MiniMagick (Source code). I guess, as the error message says, your server cannot find executable "identify".
Make sure that your ENV['PATH'] has the path to where the "identify" exists.
I'm running into the same problem.
it works flawlessly on my localhost, but on the server (windows 2012), it only works as a rake task. when run inside the application, then it fails saying
NoMethodError (undefined method `resize' for #<MiniMagick::Image:0x28c3260>):
Unfortunately, the path variable is set...
I got it to work by doing the minimagick-stuff inside the model instead of the controller.... nasty workaround.

Unable to generate rails footnote

I am trying to install debug tool called rails-footnotes on Rails 3.0 following instruction on GitHub. A check running bundle show rails-footnotes show that I got rails-footnotes-3.7.4 installed. However, when I run
rails generate rails_footnotese:install
>>Could not find generator rails_footnotese:install.
I hope someone experienced the same issue might help me out.
Thank you.
Version 3.7.4 doesn't use a generator, only the newer 3.7.5 (which hasn't been released yet) does. Also, the README has a typo; it should be rails_footnotes:install, not rails_footnotese:install (there is already a pull request to fix this).
If you want to stay on the stable 3.7.4, all the generator command does is add the config/initializers/rails_footnotes.rb file with the same content from the README:
if defined?(Footnotes) && Rails.env.development?
Footnotes.run! # first of all
# ... other init code
end
and a .rails_footnotes file with this:
#this code temporarily disables notes for all controllers
# Footnotes::Filter.notes = []
Otherwise, use the git version to make the generator work:
gem 'rails-footnotes', :git => "git://github.com/josevalim/rails-footnotes.git"

Rails + Heroku + Jammit

I'm working to install Jammit on my Rails 3 app and then to deploy to Heroku.
I installed the Jammit Gem, and configured assets.yml just fine, it works on dev. But when I pushed to heroku, the files were 404'ing.
Jammit's Usage instructions say: "You can easily use Jammit within your Rakefile, and other scripts:
require 'jammit'
Jammit.package!
I'm not following where/how that works. Running Jammit in my sites command like on the Mac yields a command not found.
Any Jammit users able to help me understand how to move to production with Jammit?
Thanks
I'm using jammit on a Rails 3.0.7 app, on Heroku
gem "jammit", :git => "git://github.com/documentcloud/jammit.git"
I have this in a rake file, to package up the assets before I commit/deploy
desc 'jammit'
task :jam => :environment do
require 'jammit'
Jammit.package!
end
And this in .git/hooks/pre-commit so it is done automatically
echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*
By default, the expires time on Heroku was only 12hrs, to increase it (because I have a cache-busting scheme that I am confident in) I put this in config/initializers/heroku.rb
module Heroku
class StaticAssetsMiddleware
def cache_static_asset(reply)
return reply unless can_cache?(reply)
status, headers, response = reply
headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
build_new_reply(status, headers, response)
end
end
end
To decrease the load on my Heroku Rails server, I am also using a free account at CloudFlare which provides a lightweight, reverse-proxy/cdn, with some decent analytics and security features.
When I get around to caching common content, this thing is really gonna scream!
You could, as I do, use jammit force to pack your assets, upload everything to s3 and define an asset host(s) in rails. This has the added advantage of keeping your slug smaller and more responsive as you can add your public directory to .slugignore .
Alternatively you'll need to work out how to make the heroku version work due to the read only file system.
You can also use a git pre-commit hook to ensure your assets are packaged prior to pushing to heroku (or any server). See https://gist.github.com/862102 for an example. You can copy that file to .git/hooks/pre-commit in your project directory.
this one is the solution
https://github.com/kylejginavan/heroku_jammit
Heroku has a read-only file system, so Jammit is unable to actually store compressed and minified CSS/JS files.
Here is a very good article on the challenge of asset packaging on heroku: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

Resources