jnordberg / gif.js

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

Using with requirejs #59

Open joedborg opened 8 years ago

joedborg commented 8 years ago

Hi, I'm trying to use this library with require. I have added both files (gif and gif.worker) to the define and confirmed they are loaded in order (with a shim). The problem is, everytime I call render, it tries to import it by URL still:

10:55:26.393 spawning worker 0 gif.js:1:3912
10:55:26.384 ReferenceError: index is not defined
10:55:26.439 GET 
http://192.168.215.150/gif.worker.js [HTTP/1.1 404 NOT FOUND 21ms]
10:55:26.453 NetworkError: Failed to load worker script at "gif.worker.js"

Require config is:

        'gif': '../libraries/gif/gif',
        'gifworker': '../libraries/gif/gif.worker',
        'gif': { exports: 'gif', deps: [] },
        'gifworker': { exports: 'gifworker', deps: ['gif'] },

If I change exports to 'gif.worker', I get:

g is undefined

Any ideas?

kieranoreilly commented 8 years ago

When you instantiate the new object do you explicitly specify the location of the workerScript ? For instance: gif = new GIF({ repeat: 0 workers: 16, quality: 30, workerScript: "/js/gif.worker.js" });

Try specifying workerScripts path

dmorehead commented 8 years ago

Hi, ..trying to just use the dist/gif.js & dist/gif.worker.js
..tried to specify a path as kieranoreilly suggests: ... workerScript: "/js/gif.worker.js" ..also tried just putting them in the same dir as my html but get the same error "ReferenceError: index is not defined"

..any help would be absolutely appreciated

stevenfabre commented 7 years ago

I can't make it work either. All I want to do really is require('./gifWorker') and make sure that this get bundled into one JS. Right now, I have no idea how to make this work.

Help would be appreciated :)

dmorehead commented 7 years ago

I did get it to run eventually, ..cant remember what the problem was? happy to see v2.0 but looks like it hasnt merged the fix for #46 (my real issue) ..here is my working snippet this.GIF = new GIF({ repeat: 0, transparent: 'rgba(0, 0, 0, 0)', //still does not handle transparency correctly workers: 4, workerScript: 'ui/lib/gif.worker.js', dither: 'FloydSteinberg-serpentine', width: renderRezW, height: renderRezW / renderRatio,
quality: 15 });