Open afnanz7634 opened 1 year ago
We should consider supporting gifs under the hood Here's an example using gifler (which is very old...) There are more options:
A simple lookup gave these results
@ShaMan123 It works on the first initial render of canvas When I load canvas from JSON or I do undo and redo using fabric-history plugin . It doesn't animate the gif it only loads the first frame of gif. please give me an estimate when this gif feature will be available because my client need it very badly and i'm stuck on it please help
Did you look at what I did???? There is no estimate.
yes i look and used your code into my fabric app https://editortoolvue.herokuapp.com/ please have a look try to load the gif and then use undo or redo function you will see the the animation stops
no thanks
You should create a subclass of Image and incorporate my code into it Without that every time you init an Image you must init the gif rendering as well
@ShaMan123 Well I didn't get your point if you give me an example code of it that would be great thanks
@afnanz7634 the gifs do not render on canvas natively, they did some years ago. The solutions are either:
Said so, we can look at publishing a clear example of how to obtain that, with the right priority since we are in the middle of a large rewrite.
Supporting gif animation or videos for your app means the browser is stuck in a continuos render loop that needs to be coordinated with multiple gifs/video, so please consider some remediation for performace reasons ( that are ux related, and maybe i m not the best person to suggest those )
I think fabric can export GIF, VIDEO etc. VIDEO for sure, GIF maybe an example as @asturur suggested is enough
yes fabric can export video but is cpu dependant. i made a codepen some time ago, let me see if i can pull it out
A possible solution - more a workaround - could be an overlay of SVG-Graphics. SVG Graphics can reference an (animated) GIF. You can manipulate the GIF by copying the properties of the fabric.js shape to the SVG GIF. If your animation is not a "video" but a simpler animated graphic, you could use an animated SVG.
How to manipulate the SVG is shown in this example:
On top is the usual fabric.js canvas with some objects to manipulate - including an animated SVG-Graphic and an animated GIF (the horse). Below are the corresponding SVG objects with copied properties.
Here you play it yourself and examine the (fairly simple) code: jsfiddle.
In your case the SVG GIF must be stacked above the fabric.js canvas.
In fact, I think it would be possible to replace the whole canvas rendering with a much simpler SVG rendering: https://github.com/fabricjs/fabric.js/discussions/8424
The @ShaMan123 solution is great for rendering But do you think there is a simple implementation to export the result canvas to a gif so you dont lose the animations inside?
Hello I'm creating an editor tool in which i want to add gif inside the canvas . the problem i'm getting is When i add gif inside canvas it load it's first frame only it didn't animate it . I've used couple of solutions from stack overflow but didn't work.
I want you add a new feature to add gif in fabric canvas thanks