npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gif-canvas-renderer

v1.0.0

Published

library to parse gif and render gif flawlessly on canvas

Downloads

85

Readme

GIFCanvasRenderer

A simple GIF renderer on canvas

We needed an efficient GIF renderer on canvas for our live classroom at Vedantu There are some libraries like libgif but it has many memory leaks and we found it very inefficient.

we came across an amazing GIF Parser by Matt Way gifuct-js

It is amazingly efficient and parses the next frame based on what is changed from previous one hence less pixel change on canvas at run time.

This library uses gifuct-js internally to parse the gif and hence render the gif on canvas

Usage

Installation:

npm install gif-canvas-renderer

-html

<canvas id="canvas-element"></canvas>

-gifRenderer

import GIFRenderer from gif-canvas-renderer

const gifObject = new GIFRenderer({
    gifSource: gifURL,
    canvasElement: document.getElementById('canvas-element'),
    renderGif: true,
    onFrameChange: (imageData) => {
      // find canvas element
      const canvasElm = document.getElementById('canvas-element')
      const ctx = canvas.getContext('2d');
      // render the imagedata on canvas
      ctx.putImageData(imageData.data, 20, 20);
    },
  });

  //call load() to start parsing

  gifObject.load(()=>{
      //callback
      console.log('do something')
  })

Constructor properties

| Option | Description | |---------------------|-----------------------------------------------------------------------| | gifSource | url of the gif file | | onFrameChange | function is called on every frame change with ImageData structure of ImageData is {currentIndex: current_frame_index, data: ImageData, totalFrames: total_frames_in_the_gif } | | canvasElement | canvas html element | | renderGif | true if gif is needed to be rendered on canvas | | handleOnCompleteLoop| function gets called once loop is completed , parameters are iterationCount = current_Count_loop, length = total_frames | | delay | delay between two frames to render |

Utility methods

| Methods | Description | |---------------------|-----------------------------------------------------------------------| | stopParsingGIF | stop parsing gif | | getLength | total frame length of the gif | | play | method to play the gif | | pause | method to pause the gif | | isPlaying | returns true if gif is playing otherwise false |