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
How to show animated gif image? #560
Comments
Perhaps try calling |
Ok, I have a solution that worked for me. You need to add the gif as an element on the page so that the browser knows to update the image when it is on the canvas. Its a strange fix, but if you make the height 0 and dynamically add it with javascript then it shouldn't affect you that much.
Whenever I googled how to do this with fabricjs I always ran into this page, hopefully now it will help someone else save time. |
Just to update, the solution given by @rnw159 no longer seems to work (Fabric 1.6.2). If anybody else has a solution to this I'd love to hear it, otherwise it looks like converting GIFs into sprite sheets and animating that way might be the only reliable way to achieve this. |
@TomFromThePool : did you find a solution to use gif in the canvas ? Even if i suppose using a sprite is the only way. |
Hi @kangax, I tried the gif on canvas as suggested by you. It is as similar like video element. But unfortunately, img element is not refreshing with renderAll(). Below my code is given. Please help. This is supper urgent. <img src="https://img.clipartfest.com/4ed31b38da845a45da975eaa495310ac_-bubblesgif-animated-bubbles-clipart_290-200.gif" #effect> this.canvas.add(new fabric.Image(this.effect.nativeElement, {subtype: "fx",top:0, left:0, height: 300, width: 300})); function render() { |
I think it's a limitiation added to the chrome Browser. The renderAll() continuiosly added doesn't work with Chrome. |
Still nothing, eh? Looks like conversion is the way to go then.. |
Some browsers want the gif to be in dom to play it. Did you try of that fix? |
I have. It does not work consistently across all browsers 😞 |
Still no solutions 😢 ? |
It has nothing to do with fabric.js. It depends on the browser, if the Canvas-element refreshes animated GIFs. So you have to ask Mozilla, Google and Microsoft to enhance their browsers. |
did you try appending the gif to the dom and see if something change? |
No. When I load an animated GIF with Safari, the animation is progressing with Some answers at StackOverflow and other sources say, that only Safari refreshes animated GIFs in a Canvas element. They generally hint at sprites as a work-around or to overlay them in front of the Canvas with CSS tricks. Blindman67 at StackOverflow gives an example to decode the animated GIF into single images and play them at the Canvas. It is memory hungry as each frame is converted to a full RGBA image, making the loaded GIF significantly larger than the GIF file size. I haven't tried it myself, postponed this feature in my app (even thouh it would be cool). |
try to append it to DOM, it could just play. |
Appen the gif to an image element in the dom ( without hiding as a test ) then use that imageElement ( not the src ) to initialize a fabric.Image element. |
Ok, thanks for the hint. Currently I'm working on the upgrade to Release 2, but I will report back later. |
Gave it a quick try, but of no avail (Firefox 62): |
Yeah i see it does not work
Il giorno lun 15 ott 2018 alle ore 15:49 awehring <notifications@github.com>
ha scritto:
… Gave it a quick try, but of no avail (Firefox 62):
http://jsfiddle.net/awehring/ucat3jh6/1/
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#560 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABI4QKTtu0_fkDKSdWAfz0P0s0xdnjEyks5ulJJcgaJpZM4Ak40_>
.
|
Any update on this issue? |
I don't expect one. It is a limitation of most browsers. (See my answer above, Oct. 15th, 2018) As a workaround you can use animated sprites. Here is an example with fabric.js: http://fabricjs.com/animated-sprite Here is an explanation of the technique: http://www.williammalone.com/articles/create-html5-canvas-javascript-sprite-animation/ |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Here is my implementation, made it to deal with stickers, so it's very efficient with small Gifs, not so well with larger ones (memory limits). https://codesandbox.io/s/red-flower-27i85 (Did my best to make the code as clear as possible, adding comments where needed) Using two methods, the first As a bonus you can set a Hope this will help any one, Fabir.js is awesome thanks to @asturur and all the contributors for this great library. |
Thank you so much @local-dev-31 for your solution, you saved me!! |
With cdn It is not working I want without node js |
I was thinking about a solution with animated SVG. And - to my surprise - it works quite well. You can embed the animated GIF in a SVG and add it as a fabric.js image to the canvas. A little effort might be necessary to set properties. Could be a good solution for many use cases. Besides animated GIFs, some other SVG features can be used (animated graphics, 3D lighting, etc.). The whole idea is explained in the discussion area here: #8424 A working jsfiddle example is there too. |
With Raphael, I can do it just as
var paper = Raphael(domEl, 600, 600);
var img = paper.image('Images/girl.gif', 0, 0, 435, 600);
but in fabric, when do it as
fabric.Image.fromURL('Images/girl.gif', function (img) {
canvas.add(img);
});
the gif image is not animated, just as the discussion in http://stackoverflow.com/questions/7281646/why-does-drawing-an-animated-gif-on-canvas-only-update-after-reselecting-the-tab
in fabric, it seems related to fabric.util.requestAnimFrame.
What's the easiest way to solve it? Tks
The text was updated successfully, but these errors were encountered: