jnordberg / gif.js

JavaScript GIF encoding library
http://jnordberg.github.io/gif.js/
MIT License
4.76k stars 668 forks source link

can i use it without workers? #47

Open ZigGreen opened 9 years ago

ZigGreen commented 9 years ago

I haven't access to webworkers in my environment. How can i run gif.js entirely in main process?

1j01 commented 9 years ago

What exactly is your environment?

ZigGreen commented 9 years ago

It's kind of browser extension for the website. I can not spawn worker due to cross domain access control. However I still could instantiate WebWorker passing Blob object so I did. My solution:

    var workerStr =  "..." // worker code as a string.
    var blob;
    try {
        blob = new Blob([workerStr], {
            type: 'application/javascript'
        });
    } catch(e) { // Backwards-compatibility
        window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
        blob = new BlobBuilder();
        blob.append(response);
        blob = blob.getBlob();
    }
    var gif = new GIF({
        workers: 2,
        workerScript: URL.createObjectURL(blob),
        quality: 10
    });
ruucm commented 12 months ago

@ZigGreen thanks a lot!!