jsgif | HTML5 Canvas to GIF and Animations | Animation library
kandi X-RAY | jsgif Summary
kandi X-RAY | jsgif Summary
Based on [as3gif] Ported by [Kevin Kwok] ![This is the raw canvas element saved as a non-animated PNG] Demos/raw_canvas.png) ![This is the GIF which was generated from the canvas.] Demos/converted_animation.gif) ![This is the GIF which was generated from the canvas.] Demos/clock.gif). Since web pages can usually natively play GIFs fine, it’s only a port of the GIFEncoder portions of the library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a tween
- convert to string
- identify the DOM element
- determine the animation type
- Returns the window size
- {{{ 1 encode
- merge two objects
- Creates a new CookieTreeTree object .
- Check if a given variable exists .
- Find index of element in array .
jsgif Key Features
jsgif Examples and Code Snippets
Community Discussions
Trending Discussions on jsgif
QUESTION
I am trying to merge multiple frames from a GIF to convert them into spritesheet. I am somehow able to extract frames using libgif.js here is my code. The Canvas in which i want to put all my images is empty and is at the end i dont know what is wrong with it.
...ANSWER
Answered 2021-Aug-02 at 10:25The main issue in your solution is that you are looping through all inserted frame-images and using window.onload
with the expectation to draw images on the canvas. However, you are assigning windows.onload
on the image elements after the images have already been attached to the dom in the previous (for i = 0)
iteration, through $("#frames").append(...
. This means that your onload
handlers are getting registered after the event has already fired.
I rearranged your code into the snippet below to make sure that onload
is registered before appending the image-frames into the document.
In this solution here I created the "spritesheet" by putting the image-frames vertically one-after-the-other. Tweak the solution accordingly to create your desired "spritesheet layout".
The tricky part is that you need to set a width
and height
for the canvas in a dynamic fashion, which means you have to wait for all image-frames to be loaded
into the document and meassure their collective widths and heights.
The algorithm should be:
- Collect all widths and heights of image-frames
onload
- Calculate the total
canvas.width
andcanvas.height
depending on your desired layout (in my vertical-one-ofter-the-other solution this means to use the maximal image width as canvas width and the sum of all image heights as height. If you need a different spritesheet layout then you need to adapt this logic differently) - Draw all the images on the canvas, which by this point has enough width and height to fit all your gif-frame-images.
In my solution I did not implement this algorith, I rather hard-coded the canvas width and height after manually calculating the max-img-width and total-img-height for your particular gif example.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jsgif
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page