wkhtmltoimage-binary icon indicating copy to clipboard operation
wkhtmltoimage-binary copied to clipboard

Heroku stack-18 issue: error while loading shared libraries: libpng12.so.0: cannot open shared object file:

Open abury opened this issue 6 years ago • 13 comments

Hey guys.

Thanks for the great gem! It's been really helpful so far. Unfortunately, we've run into a bit of a snag. It looks like the binary used in this gem relies on libpng12, however, this is not pre-installed on Heroku's new stack (Based on Ubtunu 18.04).

https://devcenter.heroku.com/articles/stack-packages

What is the best way to resolve this issue? Let me know if I can help out at all 👍

abury avatar Jan 23 '19 08:01 abury

Let me do some investigation. Are you currently blocked by this?

nicholasklick avatar Jan 23 '19 14:01 nicholasklick

Hey @nicholasklick thanks for the response!. We've been blocked for a while (I don't raise a github issue unless I'm desperate 😆), but last night I tried embedding a binary with the project's bin folder and configuring it in the IMGKit initializer and it looks like that did the trick! I had to try a few different versions (and getting a binary as opposed to a .deb file was a pain. But I eventually found https://github.com/rposborne/wkhtmltopdf-heroku and used this one (version 0.12.5) Would be great to help other folks with this, so let me know if I can provide any more insight.

abury avatar Jan 23 '19 20:01 abury

I'll add some quick notes on this - our team uses Codeship, and the tests we have that rely on wkhtmltoimage have started failing. Of course, it runs fine locally, but when ssh'd into Codeship's build to debug, we get a collection of errors, printed below for your edification:

IMGKit::CommandFailedError: Command failed: /home/rof/cache/bundler/bin/wkhtmltoimage --height 400 --quality 75 --width 400 --crop-h 400 --zoom 0.7 --format jpg - -: /home/rof/cache/bundler/gems/wkhtmltoimage-binary-0.12.5/libexec/wkhtmltoimage-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

    /home/rof/cache/bundler/gems/imgkit-1.3.10/lib/imgkit/imgkit.rb:111:in `to_img'
    .
    .
    .
    rest of stack trace

When on the box:

$ gem install wkhtmltoimage-binary
Fetching wkhtmltoimage-binary-0.12.5.gem
Successfully installed wkhtmltoimage-binary-0.12.5
1 gem installed
$ wkhtmltoimage
/home/rof/cache/bundler/gems/wkhtmltoimage-binary-0.12.5/libexec/wkhtmltoimage-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory
gem list | grep wk
wkhtmltoimage-binary (0.12.5)

I think dropping to 0.12.4 might do it. I'll try it and update here!

Update: That did it. no errors with:

# Gemfile
gem "wkhtmltoimage-binary", "0.12.4"

josh-works avatar Apr 24 '19 20:04 josh-works

I see there are updated binaries for other ubuntu versions: https://wkhtmltopdf.org/downloads.html I will see if I can get those added. Likely I will deprecate Ubuntu trusty since that is EOL.

nicholasklick avatar May 07 '19 15:05 nicholasklick

libpng12 has been replaced with libpng16 on heroku-18 (https://devcenter.heroku.com/articles/stack-packages)

any update on this ? has someone been able to run this on heroku-18 ?

MathieuDerelle avatar Apr 29 '20 07:04 MathieuDerelle

@MathieuDerelle read the above comments, I've gotten it to work on heroku-18

abury avatar May 01 '20 04:05 abury

thanks @abury but it did not work for me

I've replaced gem 'wkhtmltoimage-binary by gem 'wkhtmltopdf-heroku'

and added an initializer :

IMGKit.configure do |config|
  config.wkhtmltoimage = Gem.bin_path('wkhtmltopdf-heroku', 'wkhtmltopdf-linux-amd64')
end

the error went away but the images exported from HTML were always trash : 15 bytes 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A

MathieuDerelle avatar Oct 20 '20 17:10 MathieuDerelle

removing this gem and using the buildpack https://github.com/chap/wkhtmltopdf-heroku-18-buildpack worked for me

MathieuDerelle avatar Oct 20 '20 17:10 MathieuDerelle

removing this gem and using the buildpack https://github.com/chap/wkhtmltopdf-heroku-18-buildpack worked for me

I spent hours on this. I tried using the buildpack, but never crossed my mind removing the gems. Thanks!

lanke96 avatar Dec 16 '20 18:12 lanke96

You can use the build pack heroku-buildpack-dpkg and add Debfile in the root with content: http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb

It will install the missing library on the server on deploy

rafaelp avatar Jan 06 '21 23:01 rafaelp

Hello guys I'm having the following error using heroku tesseract, does anyone know how to solve I'm using stack 20

pytesseract.pytesseract.TesseractError: (127, 'tesseract: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory')

Adilmar avatar Feb 17 '21 19:02 Adilmar