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

Image from HTML is not rendered in generated image #118

Open
Magesh-B opened this issue May 4, 2020 · 3 comments
Open

Image from HTML is not rendered in generated image #118

Magesh-B opened this issue May 4, 2020 · 3 comments

Comments

@Magesh-B
Copy link

Magesh-B commented May 4, 2020

I want to convert an HTML page into JPG image using IMGKit gem and wkhtmltoimage-binary, In my HTML page, there is a div class whose background is an image (styled inline), While converting this HTML page, the div background image is not rendered and remaining styles and contents are rendered in the generated image. I also tried IMG SRC tag in HTML, the image is not rendered if it's source is an url.

html = %Q[]

kit = IMGKit.new(html,:height => 300,:quality => 50)

img = kit.to_img

img = kit.to_img(:jpg)

file = kit.to_file('file.jpg')`

In the generated image, the img src is not rendered and it remains blank!
It could be great if anyone help me figure out how to use url in image src.

@Ev1dentSnow
Copy link

Also having this problem

@donrestarone
Copy link

experiencing the same problem here, anyone find a fix?

Here's my setup;

Gemfile

gem 'wkhtmltopdf-binary', "0.12.4"
gem "wkhtmltoimage-binary", "0.12.4"

@CarlosDomingues
Copy link

CarlosDomingues commented Dec 6, 2023

Looks like a wkhtmltopdf issue: wkhtmltopdf/wkhtmltopdf#2913
Unfortunately, wkhtmltopdf is not mantained anymore.
That said, I used the most recent workaround suggested in the issue and it worked for me:

<style>
img.emoji {
   height: 1em;
   width: 1em;
   margin: 0 .05em 0 .1em;
   vertical-align: -0.1em;
}
</style>
<script src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js"></script>
<script>window.onload = function () { twemoji.parse(document.body);}</script>

EDIT

MaxCDN has been retired and twemoji is unmaintained. I was able to keep this workaround working by using a fork:

<style>
img.emoji {
   height: 1em;
   width: 1em;
   margin: 0 .05em 0 .1em;
   vertical-align: -0.1em;
}
</style>
 <script src="https://cdn.jsdelivr.net/npm/@twemoji/api@latest/dist/twemoji.min.js"crossorigin="anonymous"></script>
<script>window.onload = function () { twemoji.parse(document.body); }</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants