jnordberg / gif.js

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

Uncaught SyntaxError: Unexpected token < #33

Closed vincerubinetti closed 10 years ago

vincerubinetti commented 10 years ago

Can anyone think of any reason I would be getting such output from gif.js?

spawning worker 0 gif.js:1 spawning worker 1 gif.js:1 starting frame 1 of 201 gif.js:1 starting frame 2 of 201 gif.js:1 Resource interpreted as Script but transferred with MIME type text/html: "file:///C:/Users/Vincent/Desktop/Software/Tools/Gyrographer/App/gif/". gif.js:1 Uncaught SyntaxError: Unexpected token <

jnordberg commented 10 years ago

Probably due to you running it from disk instead of a web server

vincerubinetti commented 10 years ago

Not the case. Thank you for the prompt response, and I apologize for the lack of detail. Was writing this very late at night and exhausted.

See here: http://vincentrubinetti.com/apps/test/Gyrographer.html Press "Export Animated GIF" and look in the console.

Here's my set up:

animate step function { animate step++ draw new canvas add frame with gif.js if animate done { render gif.js } else { setTimeout this step function 10 ms } }

It might have something to do with the htaccess... I'll fool around with that.

jnordberg commented 10 years ago

You need to set the workerScript url if it's not in the same dir as the page

vincerubinetti commented 10 years ago

I did:

encoder = new GIF({width: Canvas.width, height: Canvas.height, workers: 2, quality: 10, workerScript: 'App/gif'});

Does it have to be an absolute path?

jnordberg commented 10 years ago

it needs to be a url to the actual script, not the directory it resides in

vincerubinetti commented 10 years ago

Very good, got it working. Thank you! Perhaps you should make that clear in the workerScript description in the readme to avoid future confusion.

jnordberg commented 10 years ago

It's pretty clear already IMHO

ionull commented 7 years ago

@jnordberg Is there any suggestion to use it in a webpack project(like vuejs), since it is a one-js-file project.

jnordberg commented 7 years ago

@ionull No, not really. The worker script is loaded through the browsers loading system, maybe that can be monkeypatched to do something but i doubt it.

ionull commented 7 years ago

@jnordberg I found something like worker-loader workerjs project which will load worker from file. But in gif.js project we must use a file path instead of worker instance.

1j01 commented 7 years ago

See https://github.com/jnordberg/gif.js/issues/58, https://github.com/jnordberg/gif.js/issues/47; @ZigGreen was able to load the worker with a blob URL. You could use webpack-contrib/raw-loader or similar to dynamically inline the file in the resulting bundle.

ionull commented 7 years ago

@1j01 thanks a lot, I used file loader minutes ago, it is now working well :) Blob is not compatible well with some IE browser