Possibility to add filter to entire canvas same as for individual objects #9755
Replies: 10 comments 4 replies
-
Try using the after:render canvas hook to do that |
Beta Was this translation helpful? Give feedback.
-
Can you please share how image filter thing would be using after:render? i am not familiar with that. |
Beta Was this translation helpful? Give feedback.
-
Image filters take an image source, canvas is an image source. |
Beta Was this translation helpful? Give feedback.
-
I am not getting your last comment and I searched but could not found the example so would you mind sharing the actual code please? I am looking for example using fabric js way in webgl. |
Beta Was this translation helpful? Give feedback.
-
To be clear your description is very confusing and is unclear what you want to achieve. Is unclear if you want to apply that dynamically or just on some kind of export and what kind of performances do you expect. The first thing you can do is clone your objects as image and filter then the images. If you want to apply the filter to the canvas surface you have to do some kind of more elaborate hack involving a proxy fabricImage and an after:render event and some more stuff. Not going to explain that if i m not sure that is what you look for |
Beta Was this translation helpful? Give feedback.
-
@asturur I have already read this thing but not sure if something better exists than this. I need filter for whole canvas. I can't better explain than this. Also, let's say if object is something else(text) other than the image, it should be that only after applying filter and not image. So iterating over everything and adding them back as image and apply filter is too long and would not work as well. Let me know if fabric js can change like that for whole canvas if something is available on fabric's native code. |
Beta Was this translation helpful? Give feedback.
-
@asturur |
Beta Was this translation helpful? Give feedback.
-
Provide me a jsfiddle or a codesandbox ( that works ) with a simple canvas and a rect and a text and i ll see if i can make an example |
Beta Was this translation helpful? Give feedback.
-
If applying a filter to all your canvas is good enough then this is enough canvas.on('before:render', ({
ctx
}) => {
ctx.filter = 'blur(5px)'
}) https://jsfiddle.net/tbp7gzru/ If not you will need to use layering, that is possible but you will need to impl on top of fabric. |
Beta Was this translation helpful? Give feedback.
-
yes, that requires you to rebuild rendering
no |
Beta Was this translation helpful? Give feedback.
-
CheckList
Description
When we need to add filter to entire canvas, nothing is currently available to do this. I need the same thing how we add to objects but for entire canvas.
Above code adds brightness filter but for object only. We may be iterate over all objects but that does not look the proper way to do it. Also, getting whole image first via
toDataUrl
and applying filter to that image is not viable solution.Current State
Searched but could not found any solution to this issue.
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions