Coder Social home page Coder Social logo

rfrench / gify Goto Github PK

View Code? Open in Web Editor NEW
138.0 7.0 27.0 34 KB

JavaScript API for decoding/parsing information from animated GIFs using ArrayBuffers.

License: MIT License

JavaScript 89.11% HTML 10.89%
arraybuffer javascript gif gifs animated-gif animated-gifs exif

gify's Introduction

gify

JavaScript API for decoding/parsing information from animated GIFs using ArrayBuffers.

Why?

Once I saw vinepeek, I immediately wanted to build a similar site for animated GIFs. The only problem was, there was no way to quickly determine the duration of an animated GIF, which varies in different browsers. Thus, gify was born over a weekend.

Requirements

gify requires jDataView for reading binary files. Please pull the latest from their repository.

Methods

  • isAnimated(sourceArrayBuffer) (bool)
  • getInfo(sourceArrayBuffer) (gifInfo)

info Properties

  • valid (bool) - Determines if the GIF is valid.
  • animated (bool) - Determines if the GIF is animated.
  • globalPalette (bool) - Determines if the GIF has a global color palette.
  • globalPaletteSize (int) - Size of the global color palette.
  • globalPaletteColorsRGB ([r,g,b]) - An array of objects containing the R, G, B values of the color palette. (Beppe)
  • height (int) - Canvas height.
  • width (int) - Canvas width.
  • loopCount (int) - Total number of times the GIF will loop. 0 represents infitine. -1 represents display once.
  • images ([images]) - Array of images contained in the GIF.
  • isBrowserDuration (bool) - If any of the delay times are lower than the minimum value, this value will be set to true.
  • duration (int) - Actual duration calculated from the delay time for each image. If isBrowserDuration is false, you should use this value.
  • durationIE (int) - Duration for Internet Explorer (16fps)
  • durationSafari (int) - Duration for Safari in milliseconds (50fps)
  • durationFirefox (int) - Duration for Firefox in milliseconds (50fps)
  • durationChrome (int) - Duration for Chrome in milliseconds (50fps)
  • durationOpera (int) - Duration for Opera in milliseconds (50fps)

image Properties

  • identifier (string) - Image identifier (frame number or embeded string).
  • top (int) - Image top position (Y).
  • left (int) - Image left position (X).
  • height (int) - Image height.
  • width (int) - Image width.
  • localPalette (bool) - Image has a local color palette.
  • localPaletteSize (int) - Size of the local color palette.
  • interlace (bool) - Image is/is not interlaced.
  • delay (int) - Delay time in milliseconds.
  • text (string) - frame text. aka Plain Text Extension.
  • comments ([comments]) - Array of comment strings.
  • disposal (int) - Disposal method. (0-7). See this for more details.

Example

{
  "valid": true,
  "globalPalette": true,
  "globalPaletteSize": 256,
  "globalPaletteColorsRGB": [
    {
      "r": 50,
      "g": 82,
      "b": 120
    },
    {
      "r": 89,
      "g": 105,
      "b": 119
    },
    {
      "r": 4,
      "g": 33,
      "b": 71
    }
  ],
  "loopCount": 0,
  "height": 1610,
  "width": 899,
  "animated": true,
  "images": [
    {
      "identifier": "0",
      "localPalette": false,
      "localPaletteSize": 0,
      "interlace": false,
      "comments": [],
      "text": "",
      "left": 0,
      "top": 0,
      "width": 1610,
      "height": 899,
      "delay": 350,
      "disposal": 0
    },
    {
      "identifier": "1",
      "localPalette": true,
      "localPaletteSize": 256,
      "interlace": false,
      "comments": [],
      "text": "",
      "left": 0,
      "top": 0,
      "width": 1610,
      "height": 899,
      "delay": 350,
      "disposal": 0
    },
    {
      "identifier": "2",
      "localPalette": true,
      "localPaletteSize": 256,
      "interlace": false,
      "comments": [],
      "text": "",
      "left": 0,
      "top": 0,
      "width": 1610,
      "height": 899,
      "delay": 350,
      "disposal": 0
    },
    {
      "identifier": "3",
      "localPalette": true,
      "localPaletteSize": 256,
      "interlace": false,
      "comments": [],
      "text": "",
      "left": 0,
      "top": 0,
      "width": 1610,
      "height": 899,
      "delay": 350,
      "disposal": 0
    }
  ],
  "isBrowserDuration": false,
  "duration": 2800,
  "durationIE": 2800,
  "durationSafari": 2800,
  "durationFirefox": 2800,
  "durationChrome": 2800,
  "durationOpera": 2800
}

Resources

gify's People

Contributors

rfrench avatar tofrankie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gify's Issues

How to distinguish between loop once and loop forever?

I have three GIF images:

  • no-loopcount.gif
  • loopcount-forever.gif
  • loopcount-2.gif

Their actual LoopCount is as follows (use Gifsicle):

  • no-loopcount.gif showing every frame once.
  • loopcount-forever.gif showing forever (infitine).
  • loopcount-2.gif showing every frame thrice.

image

But when I use gify, the result is:

image

The LoopCount parsed by no-loopcount.gif and loopcount-forever.gif are both 0.

Is this a bug, or can't tell the difference?

Here's how I do it:

const getGifInfo = async file => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onload = event => {
      const URL = window.URL || window.webkitURL
      const blob = new Blob([event.target.result])
      const blobURL = URL.createObjectURL(blob)

      const img = new Image()
      img.src = blobURL
      img.onload = () => {
        const gifInfo = window.gify.getInfo(reader.result)
        resolve(gifInfo)
      }
      img.onerror = event => {
        reject(event)
      }
    }
    reader.readAsArrayBuffer(file)
  })
}

Thanks.

width/height are switched

I guess this repo is inactive but for everyone forking it / building upon it: width and height are switched.

Those two lines

gify/gify.js

Line 101 in 5ed5d01

info.height = view.getUint16(6, true);
should read

info.width = view.getUint16(6, true);
info.height = view.getUint16(8, true);

issue on loopCount

Hi,
I'm using this library, I've an issue about loopCount, seems that even if is set a value of loops inside the gif I've always back loopCount=0.
Attached example is an animated gif with two frames (one sec each) and 15 loops.

astrifox_160x600-30

Thanks
Maurizio

loopCount 120

hi, I'm trying to get info from a gif and i'm obtaining loopCount:120 but i set when i create the gif loopCount:3 in photoshop.

Do you know why i getting it?
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.