How to use omggif - 10 common examples

To help you get started, we’ve selected a few omggif examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sole / Animated_GIF / dist / Animated_GIF.js View on Github external
function generateGIF(frames, callback) {

        // TODO: Weird: using a simple JS array instead of a typed array,
        // the files are WAY smaller o_o. Patches/explanations welcome!
        var buffer = []; // new Uint8Array(width * height * frames.length * 5);
        var globalPalette;
        var gifOptions = { loop: repeat };

        // Using global palette but only if we're also using dithering
        if(dithering !== null && palette !== null) {
            globalPalette = palette;
            gifOptions.palette = globalPalette;
        }

        var gifWriter = new GifWriter(buffer, width, height, gifOptions);

        generatingGIF = true;

        frames.forEach(function(frame, index) {

            var framePalette;

            if(!globalPalette) {
               framePalette = frame.palette;
            }

            onRenderProgressCallback(0.75 + 0.25 * frame.position * 1.0 / frames.length);
            gifWriter.addFrame(0, 0, width, height, frame.pixels, {
                palette: framePalette,
                delay: delay
            });
github sole / Animated_GIF / src / Animated_GIF.js View on Github external
function generateGIF(frames, callback) {

        // TODO: Weird: using a simple JS array instead of a typed array,
        // the files are WAY smaller o_o. Patches/explanations welcome!
        var buffer = []; // new Uint8Array(width * height * frames.length * 5);
        var globalPalette;
        var gifOptions = { loop: repeat };

        // Using global palette but only if we're also using dithering
        if(dithering !== null && palette !== null) {
            globalPalette = palette;
            gifOptions.palette = globalPalette;
        }

        var gifWriter = new GifWriter(buffer, width, height, gifOptions);

        generatingGIF = true;

        frames.forEach(function(frame, index) {

            var framePalette;

            if(!globalPalette) {
               framePalette = frame.palette;
            }

            onRenderProgressCallback(0.75 + 0.25 * frame.position * 1.0 / frames.length);
            gifWriter.addFrame(0, 0, width, height, frame.pixels, {
                palette: framePalette,
                delay: delay
            });
github rauchg / clif / lib / process.js View on Github external
png.on('parsed', () => {
        if (!this.encoder) {
          let { width, height } = png;
          this.width = width;
          this.height = height;
          this.gif = [];
          this.encoder = new GIF(this.gif, width, height, { loop: 0 });
        }

        let { width, height, quality } = this;
        let out = processFrame(png.data, width, height, quality);

        this.encoder.addFrame(0, 0, width, height, out.pixels, {
          // by spec, delay is specified in hundredths of seconds
          delay: Math.round(delay / 10),
          palette: out.palette
        });

        resolve(true);
      });
      png.write(buf);
github jhuckaby / canvas-plus / lib / format / gif.js View on Github external
// GIF requires palette size be a power of 2, so pad with black
		while ((num_colors & (num_colors - 1)) || (num_colors < 2)) {
			palette_data.push( 0x000000 );
			num_colors++;
		}
		
		this.logDebug(6, "Compressing into GIF", {
			palette_size: num_colors,
			transparent_index: transparent_index
		} );
		
		// construct GIF buffer
		var buf = Buffer.alloc( (width * height) + 1024 );
		var gf = null;
		try {
			gf = new OMGGIF.GifWriter( buf, width, height, { palette: palette_data } );
			gf.addFrame( 0, 0, width, height, iq_pixels, { transparent: transparent_index } );
		}
		catch (err) {
			return this.doError('gif', "GIF compression error: " + err, callback);
		}
		
		// and we're done!
		this.logDebug(6, "GIF compression complete");
		callback( false, buf.slice(0, gf.end()) );
	}
github jtlapp / gifwrap / src / gifcodec.js View on Github external
function _encodeGlobal(frames, spec, bufferSizeEst, globalPalette) {
    // would be inefficient for frames to lookup colors in extended palette 
    const extendedGlobalPalette = {
        colors: globalPalette.colors.slice(),
        usesTransparency: globalPalette.usesTransparency
    };
    _extendPaletteToPowerOf2(extendedGlobalPalette);
    const options = {
        palette: extendedGlobalPalette.colors,
        loop: spec.loops
    };
    let buffer = new Buffer(bufferSizeEst);
    let gifWriter;
    try {
        gifWriter = new Omggif.GifWriter(buffer, spec.width, spec.height,
                            options);
    }
    catch (err) {
        throw new GifError(err);
    }
    for (let i = 0; i < frames.length; ++i) {
        buffer = _writeFrame(gifWriter, i, frames[i], globalPalette, false);
    }
    return new Gif(buffer.slice(0, gifWriter.end()), frames, spec);
}
github brainshave / sharpvg / gif.js View on Github external
function pixels (file_content) {
  var img = new GifReader(file_content);

  var w = img.width, h = img.height;

  var data = new Uint8Array(w * h * 4);
  img.decodeAndBlitFrameRGBA(0, data);

  return split(data, w, h);
}
github processing / p5.js / src / image / loading_displaying.js View on Github external
function _createGif(
  arrayBuffer,
  pImg,
  successCallback,
  failureCallback,
  finishCallback
) {
  const gifReader = new omggif.GifReader(arrayBuffer);
  pImg.width = pImg.canvas.width = gifReader.width;
  pImg.height = pImg.canvas.height = gifReader.height;
  const frames = [];
  const numFrames = gifReader.numFrames();
  let framePixels = new Uint8ClampedArray(pImg.width * pImg.height * 4);
  if (numFrames > 1) {
    const loadGIFFrameIntoImage = (frameNum, gifReader) => {
      try {
        gifReader.decodeAndBlitFrameRGBA(frameNum, framePixels);
      } catch (e) {
        p5._friendlyFileLoadError(8, pImg.src);
        if (typeof failureCallback === 'function') {
          failureCallback(e);
        } else {
          console.error(e);
        }
github scijs / get-pixels / node-pixels.js View on Github external
function handleGIF(data, cb) {
  var reader
  try {
    reader = new GifReader(data)
  } catch(err) {
    cb(err)
    return
  }
  if(reader.numFrames() > 0) {
    var nshape = [reader.numFrames(), reader.height, reader.width, 4]
    try  {
      var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3])
    } catch(err) {
      cb(err)
      return
    }
    var result = ndarray(ndata, nshape)
    try {
      for(var i=0; i
github seleb / bitsy-hacks / src / character portraits animated.js View on Github external
.then(function (arrayBuffer) {
				var data = new window.Uint8Array(arrayBuffer);
				var reader = new GifReader(data);
				var numFrames = reader.numFrames();
				var width = reader.width;
				var height = reader.height;
				var prev = document.createElement('canvas');
				prev.width = width;
				prev.height = height;
				var prevCtx = prev.getContext('2d');
				var frames = [];
				var duration = 0;
				for (var i = 0; i < numFrames; ++i) {
					var canvas = document.createElement('canvas');
					canvas.width = width;
					canvas.height = height;
					var ctx = canvas.getContext('2d');
					var imgData = ctx.createImageData(width, height);
					reader.decodeAndBlitFrameRGBA(i, imgData.data);
github scijs / get-pixels / dom-pixels.js View on Github external
function handleGif(data, cb) {
  var reader
  try {
    reader = new GifReader(data)
  } catch(err) {
    cb(err)
    return
  }
  if(reader.numFrames() > 0) {
    var nshape = [reader.numFrames(), reader.height, reader.width, 4]
    var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3])
    var result = ndarray(ndata, nshape)
    try {
      for(var i=0; i

omggif

omggif is a JavaScript implementation of a GIF 89a encoder and decoder.

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis

Popular omggif functions