'use strict' var path = require('path') var ndarray = require('ndarray') var GifReader = require('omggif').GifReader var pack = require('ndarray-pack') var through = require('through') var parseDataURI = require('data-uri-to-buffer') function defaultImage(url, cb) { var img = new Image() img.crossOrigin = "Anonymous" img.onload = function() { var canvas = document.createElement('canvas') canvas.width = img.width canvas.height = img.height var context = canvas.getContext('2d') context.drawImage(img, 0, 0) var pixels = context.getImageData(0, 0, img.width, img.height) cb(null, ndarray(new Uint8Array(pixels.data), [img.width, img.height, 4], [4, 4*img.width, 1], 0)) } img.onerror = function(err) { cb(err) } img.src = url } //Animated gif loading 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