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

When using Transparent Color and Background, Nothing Renders

Open BrandonQDixon opened this issue 4 years ago • 12 comments

Expected Behavior

The image should render as it appears on the screen, such as: image

Current Behavior

Nothing renders except for transparency: image

Steps To Reproduce

  1. Create a div and apply these css rules to it:
#logo {
    color: transparent;
    background: linear-gradient(#3294cd, #a85c34);
    background-clip: text;
    -webkit-background-clip: text;
    font-style: italic;
    font-weight: bold;
    font-family: Aladin;
    filter:  brightness(100%) contrast(140%) saturate(140%);
}
  1. Attempt to generate an image.

Additional Context

I'm running this in an Angular project via npm install. I've successfully used this in other projects, but this is the first project where the text color is transparent and the background only is what is actually being displayed. I am running this on Chrome, Windows 11.

BrandonQDixon avatar Jan 15 '22 22:01 BrandonQDixon

👋 @BrandonQDixon

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 avatar Jan 15 '22 22:01 biiibooo

I have same issue

0xpierson avatar Jan 27 '22 12:01 0xpierson

Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Thanks for being a part of the Antv community! 💪💯

biiibooo avatar Feb 17 '22 01:02 biiibooo

I've created a quick reproduction in code sandbox: https://codesandbox.io/s/boring-water-ng4hqh?file=/src/index.js

This is the result:

Screen Shot 2022-03-22 at 10 20 45 PM

Anyway, I can help? 😁

yagudaev avatar Mar 23 '22 05:03 yagudaev

From a bit of digging around it seems the SVG that get generated does not contain the key background-clip or -webkit-background-clip. Perhaps it is something during the cloning process?

yagudaev avatar Mar 23 '22 07:03 yagudaev

After a lot more digging around, it is a chrome bug in how it sets vendor prefixes programmatically.

https://github.com/facebook/react/issues/14200

Basically, Chrome assumes it supports background-clip and just removes the vendor prefix. Seems like it has been the case since at least 2018.

Worse, it sometimes would decide to use a shorthand CSS property background instead of background-clip, background-image, etc. This will make the shorthand property invalid which is why you are seeing a transparent background @BrandonQDixon.

There are 3 possible solutions:

  1. Pull text out of SVG foreignObject and into a <text> and <linear-gradient> attributes (note that Figma doesn't support gradient fills in SVG text elements, so instead of using <mask /> and <rect /> will do it, got the idea from: https://github.com/felixfbecker/dom-to-svg).

  2. Replace text HTML gradient nodes with SVGs as in no.1, and let the library still do the same thing with foreignObject. This avoids relying on Chrome's CSS rendering in favour of SVG rendering.

  3. Inline-styles in XML string and use XML (not HTML) to construct foreignObject string.

Overall, thank you @bubkoo for a great library. The reliance on SVG foreign object for all image functions is brilliant and once chrome fixes this bug and as it evolves this lib will continue to generate accurate browser based snapshots 😁.

yagudaev avatar Apr 05 '22 19:04 yagudaev

Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Thanks for being a part of the Antv community! 💪💯

biiibooo avatar Apr 26 '22 01:04 biiibooo

Thanks for this hacked solution

kurzenkov-globant avatar Apr 26 '22 18:04 kurzenkov-globant

@kurzenkov-globant I have it working in production at http://conceptual.so/ 😁

yagudaev avatar May 11 '22 04:05 yagudaev

Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Thanks for being a part of the Antv community! 💪💯

biiibooo avatar Jun 01 '22 02:06 biiibooo

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! 💪💯

biiibooo avatar Jul 12 '22 02:07 biiibooo

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

biiibooo avatar Jul 13 '23 01:07 biiibooo