0

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 then also.

html = %Q[<html><body><div style="background-image: url('https://upload.wikimedia.org/wikipedia/en/thumb/4/47/Iron_Man_(circa_2018).png/250px-Iron_Man_(circa_2018).png')">Vanakkam</div></body></html>]

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

img = kit.to_img

img = kit.to_img(:jpg)

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

I can't figure out how to make this work and are there any methods in rails to complete this job?

1 Answers1

0

Can you try to create your HTML page instead of using a string array?

Then you can just simply use File.new as the documentation suggests:

kit = IMGKit.new(File.new('/path/to/mysite.html'),:height => 300,:quality => 50)
IDGM5
  • 179
  • 1
  • 1
  • 11
  • Thanks for this idea, But I can't figure out where to put my HTML file from the documentation, I created a folder and changed the address towards it, but the file path is not accessible by File.new – Magesh Bhaskaran May 03 '20 at 11:44
  • I tried what you have suggested, still the image from html is not rendered! – Magesh Bhaskaran May 03 '20 at 12:20