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

mix-blend-mode not rendered #580

Open
Cristian-L opened this issue Apr 25, 2015 · 13 comments
Open

mix-blend-mode not rendered #580

Cristian-L opened this issue Apr 25, 2015 · 13 comments
Labels

Comments

@Cristian-L
Copy link

@Cristian-L Cristian-L commented Apr 25, 2015

I am trying to use mix-blend-mode on some of the divs to get some nice effects. However, html2canvas does not render it at all. Any suggestions or workarounds, please?

@brcontainer
Copy link
Contributor

@brcontainer brcontainer commented Sep 13, 2015

Please read this:

https://github.com/niklasvh/html2canvas#browser-compatibility

As each CSS property needs to be manually built to be supported, there are a number of properties that are not yet supported.

I hope it is possible to implement this in the near future :)

@jackuro
Copy link

@jackuro jackuro commented Jan 3, 2017

hi cristian have the same issue, did you found any solution?

@jackuro
Copy link

@jackuro jackuro commented Jan 3, 2017

i see it already looks like the render does the image solid forgetin the css mix-blend-mode how can i fix that? its not a browser problem, thank you @brcontainer @niklasvh

@brcontainer
Copy link
Contributor

@brcontainer brcontainer commented Jan 4, 2017

@jackuro There is no way to fix something that has not been implemented. I really think there is a lack of collaboration in the project, there are many "forks", but few "pullrequests" that are useful. :(

@niklasvh niklasvh added the Feature label Dec 11, 2017
@egfx
Copy link

@egfx egfx commented Aug 1, 2018

I really wonder if mix-blend-mode is possible. It would be a very welcome addition. Any hints on where to start the implementation?

@MatthijsMud
Copy link

@MatthijsMud MatthijsMud commented Oct 1, 2018

CanvasRenderingContext2D has a property that could possibly be used for the desired effect: globalCompositeOperation. All allowed values for mix-blend-mode are valid values for the given property.

Setting the property when the browser doesn't support it, should be no different from the current implementation. In that regard it has a nice fallback. So I expect something akin to the following is all that is needed to implement the feature.

var temp = ctx.globalCompositeOperation;
ctx.globalCompositeOperation = window.getComputedStyle(node).mixBlendMode;

// ...

ctx.globalCompositeOperation = temp;

As to where this piece of code needs to be placed... I have little to no idea, given I'm not all that well versed in the project (yet). It should be before the element and its children are rendered, at which point more properties are likely to be set.

Another issue, pertaining background-blend-mode, can probably be solved in a similar way; the moment the context is restored differs.

@jechazelle
Copy link

@jechazelle jechazelle commented Jul 7, 2019

Hi,
Do you have any news about mix-blend-mode support please or how can I use it please ?

@brcontainer
Copy link
Contributor

@brcontainer brcontainer commented Jul 7, 2019

@jechazelle Hi. If you are using the latest version of html2canvas and it still does not support a specific CSS property is because it has not yet been implemented, all CSS properties will probably have priority, but every day a new property or functionality appears and you have to understand that you do not plan a one, develops what is possible within the necessary time.

What annoys me is seeing so many forks without collaboration, just used as useless backups (since forks do not go with versioning on github-web, only if you use a webhook to force this, but most do not even really know how webhooks work, so probably the forks are even just for outdates backups).

The only solution is to go testing and if you have experience with this and want to collaborate with the project (fork or pull-request), it would be very helpful because there are many features and more people working better.

See https://github.com/niklasvh/html2canvas#browser-compatibility:

As each CSS property needs to be manually built to be supported, there are a number of properties that are not yet supported.

@TheSevDev
Copy link

@TheSevDev TheSevDev commented May 28, 2020

I have a quick and dirty solution to change the mix-blend-mode. In my case I used overlapping images with mix-blend-mode: multiply. Simply insert the code below at line 6157:
this.ctx.globalCompositeOperation = 'multiply';
html2canvas-change
It's hardcoded and changes the blend-mode for all elements inside the canvas though...
Kudos to @MatthijsMud

@TheSevDev
Copy link

@TheSevDev TheSevDev commented Oct 5, 2020

I managed to add some further mix-blend-mode functionality. It's still quick and dirty but at least it's now possible to have different blend modes for different elements. The mix-blend-mode «multiply» seems to work fine for images and text – others such as «exclusion» lead to unexpected results. Below are the code snippets I've added:
Bildschirmfoto 2020-10-05 um 23 26 12
Bildschirmfoto 2020-10-05 um 23 26 57
Bildschirmfoto 2020-10-05 um 23 27 25
Bildschirmfoto 2020-10-05 um 23 27 45

This is not a proper solution at all – but maybe it helps someone in the meantime.
Code Snippets:

var mixBlendMode = { name: 'mix-blend-mode', initialValue: 'normal', prefix: false, type: PropertyDescriptorParsingType.IDENT_VALUE, parse: function (mixBlendMode) { return mixBlendMode } };

this.mixBlendMode = parse(mixBlendMode, declaration.mixBlendMode);

_this.ctx.globalCompositeOperation = styles.mixBlendMode;

this.ctx.globalCompositeOperation = container.styles.mixBlendMode;

@tayfunerbilen
Copy link

@tayfunerbilen tayfunerbilen commented Oct 24, 2020

I managed to add some further mix-blend-mode functionality. It's still quick and dirty but at least it's now possible to have different blend modes for different elements. The mix-blend-mode «multiply» seems to work fine for images and text – others such as «exclusion» lead to unexpected results. Below are the code snippets I've added:
Bildschirmfoto 2020-10-05 um 23 26 12
Bildschirmfoto 2020-10-05 um 23 26 57
Bildschirmfoto 2020-10-05 um 23 27 25
Bildschirmfoto 2020-10-05 um 23 27 45

This is not a proper solution at all – but maybe it helps someone in the meantime.
Code Snippets:

var mixBlendMode = { name: 'mix-blend-mode', initialValue: 'normal', prefix: false, type: PropertyDescriptorParsingType.IDENT_VALUE, parse: function (mixBlendMode) { return mixBlendMode } };

this.mixBlendMode = parse(mixBlendMode, declaration.mixBlendMode);

_this.ctx.globalCompositeOperation = styles.mixBlendMode;

this.ctx.globalCompositeOperation = container.styles.mixBlendMode;

I tried your solution but still not working, any suggestion?

@TheSevDev
Copy link

@TheSevDev TheSevDev commented Oct 24, 2020

@tayfunerbilen Please try again by using the same modified library file as I use: html2canvas-with-mix-blend-mode.js.zip
I created a simple CodePen: https://codepen.io/SevKel/pen/ZEOLPEg

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

Successfully merging a pull request may close this issue.

None yet
9 participants