html-to-image icon indicating copy to clipboard operation
html-to-image copied to clipboard

How can I render image with `hidden` element?

Open tinnguyen1296 opened this issue 2 years ago • 8 comments

I have a component (only use to render image) is hidden element, but when I export it, the image rendered with empty content, how can I render image with hidden element

tinnguyen1296 avatar Dec 29 '22 04:12 tinnguyen1296

👋 @tinnguyen1296

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

biiibooo[bot] avatar Dec 29 '22 04:12 biiibooo[bot]

I met this issue also, and found a solution: Use z-index

hoppergee avatar Jan 04 '23 11:01 hoppergee

@hoppergee Can you explain it more? I am facing the same issue but no idea how to use z-index to make it work. Thanks

soapwong703 avatar Jul 13 '23 10:07 soapwong703

@soapwong703 The reason of the image is not getting rendered is because browsers doesn't render hidden elements. But if we use z-index to do the hidden works instead, (like setting it to a properly value maybe -999), then the image is getting rendered. Hope it's helpful.

hoppergee avatar Jul 13 '23 23:07 hoppergee

if you are using tailwind the solution for me was to use a div with class 'sr-only' and inside it my element, if you are not using tailwind, sr-only does this: position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0, 0); white-space: nowrap; border-width: 0;

Esteban-Montecinos avatar Jan 13 '24 00:01 Esteban-Montecinos

You can set display to none in your css and then change it directly on render, using style option:

const blob = await toBlob(element, {
  style: {
    display: 'flex',
  },
});

datsenkoboos avatar May 09 '24 17:05 datsenkoboos

Do we have any solution for it? I am only getting blank screen with size 0KB for hidden element.

ajayv1 avatar May 26 '24 08:05 ajayv1

Do we have any solution for it? I am only getting blank screen with size 0KB for hidden element.

Same

Cybersepp avatar May 28 '24 12:05 Cybersepp