h5bp / mothereffinganimatedgif

Make your animated gifs in the browser! Oh yeah!

Home Page:https://mothereffinganimatedgif.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: Blob download for chrome

wonglok opened this issue · comments

inside omggif-worker.js
add this

var getGifBuffer = function(gif,buffer) {
    var l = gif.end();
    var uInt8View = new Uint8Array(new ArrayBuffer( l ));
    //var viewLength = uInt8View.length;
    var i;
    for (i = 0; i < l; i++) {
      uInt8View[i] = buffer[i];
    }
    return uInt8View;
  };

  var gifBuffer = getGifBuffer(gif,buffer);

and then add this line to the postMessage

self.postMessage({
    type: "gif",
    //*here*
    buffer: gifBuffer,
    data: gifString,
    frameCount: framesLength,
    encodeTime: Date.now()-startTime
});

here is code that invoke download :)

//http://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
var saveData = (function () {
  var a = document.createElement('a');
  document.body.appendChild(a);
  a.style = 'display: none';
  return function (data, fileName) {
    // var json = JSON.stringify(data),
    // var blob = new Blob([json], {type: 'octet/stream'}),
    var blob = new Blob([data], {type: 'octet/stream'}),
    url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = fileName;
    a.click();
    window.URL.revokeObjectURL(url);
    a = null;
  };
}());

            var fileName = 'gif.gif';
                        //*added buffer param*
            saveData(info.buffer, fileName);