question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting HTML containing img elements to PNG results in images not loading

See original GitHub issue

Expected Behavior

When converting HTML that contains <img> elements, the <img> elements should always complete loading before the HTML is converted to an image.

Current Behavior

In some situations, specifically with Twitter profile pictures as the source, the <img> elements do not load in time, and when the HTML is converted to a, say PNG for example, the image(s) are not present.

Some images load just fine, just not these, which kinda sucks – I need Twitter profile pics to load.

Possible Solution

This must be a result of the sequence of events that occur when a function like toPng is called. I have attempted to convert the HTML to a blob instead, and the same issue prevails.

Steps To Reproduce

  1. Create an HTML <img src="https://pbs.twimg.com/profile_images/1354479643882004483/Btnfm47p_bigger.jpg"/> element. This source is good because it is a situation where the image will not appear.
  2. Convert HTML to PNG
  3. Save PNG to computer.
Error Message & Stack Trace

<!-- Provide a log message if relevant -->

Additional Context

I am creating a basic application that allows users to paste in a link to a Tweet, where my application will then render the contents of the Tweet on a React component on a customizable background. Once they have customized the Tweet and background to their liking, they can choose to export it as a PNG.

The HTML page, showing the Tweet component: image

The resulting image (exported as PNG): image This branch contains my features I implemented. components/SnippetPreview.tsx contains the logic for exporting.

Your Environment

  • html-to-image: 1.9.0
  • OS: Windows 10, macOS, etc.
  • Browser: Firefox, Chrome, Brave, all of them.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
delia-mcommented, Jan 26, 2022

I had same issue with toJpeg and just worked round to use div and set image as a background rather than using img element This worked for me but it would be great if img element is working

0reactions
vivcat[bot]commented, Mar 28, 2022

Hey again! It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Thanks again for being part of the Antv community! 💪💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to display image when converting HTML to image
Open the HTML page (that you wish to convert to an image) in Chrome. · Right click anywhere in the background of the...
Read more >
Why can I not see the images on my website?
There are several possible reasons why your images are not showing up on your pages as expected: The image file is not located...
Read more >
Everything you need to know about images loading
Today I want to talk about how images load on the web. ... As a rule, everytime the browser encounter an img tag...
Read more >
Preventing Content Reflow From Lazy-Loaded Images
Reflow is a problem because it's a user-blocking operation. It slows down the browser by forcing it to recalculate the layout of any...
Read more >
Lazy Loading Images – The Complete Guide
Everything about Image Lazy loading - what is it, why is it important, how to implement lazy loading of images and the best...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found