Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,37 @@ ag.setSize(320, 240);
// ... etc
```

### Using as module

Install with NPM or YARN:

```bash
npm install --save animated_gif
# or
yarn add animated_gif
```

Use in your project:
```javascript
import AnimatedGIF from 'animated_gif'

const ag = new AnimatedGIF({
width: 640,
height: 480,
// Will work only if BLOB worker's code from final build
workerUrl: window.URL.createObjectURL(new Blob(['minified worker source code'], { type: 'text/javascript' }))
})

// ... use code from examples
```

## Available options

Pass an object with the desired values when creating an `Animated_GIF` instance:

- `sampleInterval`: how many pixels to skip when creating the palette. Default is 10. Less is better, but slower.
- `numWorkers`: how many web workers to use. Default is 2.
- `workerUrl`: URL to worker (default: './Animated_GIF.worker.js') (accepts BLOB if you need to use it with bundler)
- `useQuantizer`: this is `true` by default, and provides the highest quality results, at the cost of slower processing and bigger files. When this is enabled, a neural network quantizer will be used to find the best palette for each frame. No dithering is available in this case, as the colours are chosen with the quantizer too.
- `dithering`: selects how to best spread the error in colour mapping, to *conceal* the fact that we're using a palette and not true color. Note that using this option automatically disables the aforementioned quantizer. Best results if you pass in a palette, but if not we'll create one using the colours in the first frame. Possible options:
- `bayer`: creates a somewhat nice and retro 'x' hatched pattern
Expand Down
3 changes: 2 additions & 1 deletion src/Animated_GIF.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Animated_GIF(options) {
var onRenderProgressCallback = function() {};
var sampleInterval;
var workers = [], availableWorkers = [], numWorkers;
var workerUrl = options.workerUrl || './Animated_GIF.worker'
var generatingGIF = false;

// We'll try to be a little lenient with the palette so as to make the library easy to use
Expand Down Expand Up @@ -67,7 +68,7 @@ function Animated_GIF(options) {
numWorkers = options.numWorkers || 2;

for(var i = 0; i < numWorkers; i++) {
var w = new Worker('./Animated_GIF.worker');
var w = new Worker(workerUrl);
workers.push(w);
availableWorkers.push(w);
}
Expand Down