OLD | NEW |
| (Empty) |
1 | |
2 # gif.js | |
3 | |
4 JavaScript GIF encoder that runs in your browser. | |
5 | |
6 Uses typed arrays and web workers to render each frame in the background, it's r
eally fast! | |
7 | |
8 **Demo** - http://jnordberg.github.io/gif.js/ | |
9 | |
10 Works in browsers supporting: [Web Workers](http://www.w3.org/TR/workers/), [Fil
e API](http://www.w3.org/TR/FileAPI/) and [Typed Arrays](https://www.khronos.org
/registry/typedarray/specs/latest/) | |
11 | |
12 Tested in | |
13 * Google Chrome | |
14 * Firefox 17 | |
15 * Safari 6 | |
16 * Internet Explorer 10 | |
17 * Mobile Safari iOS 6 | |
18 | |
19 ## Usage | |
20 | |
21 Include `gif.js` found in `dist/` in your page. Also make sure to have `gif.work
er.js` in the same location. | |
22 | |
23 ```javascript | |
24 var gif = new GIF({ | |
25 workers: 2, | |
26 quality: 10 | |
27 }); | |
28 | |
29 // add a image element | |
30 gif.addFrame(imageElement); | |
31 | |
32 // or a canvas element | |
33 gif.addFrame(canvasElement, {delay: 200}); | |
34 | |
35 // or copy the pixels from a canvas context | |
36 gif.addFrame(ctx, {copy: true}); | |
37 | |
38 gif.on('finished', function(blob) { | |
39 window.open(URL.createObjectURL(blob)); | |
40 }); | |
41 | |
42 gif.render(); | |
43 ``` | |
44 | |
45 ## Options | |
46 | |
47 Options can be passed to the constructor or using the `setOptions` method. | |
48 | |
49 | Name | Default | Description
| | |
50 | -------------|-----------------|----------------------------------------------
------| | |
51 | repeat | `0` | repeat count, `-1` = no repeat, `0` = forever
| | |
52 | quality | `10` | pixel sample interval, lower is better
| | |
53 | workers | `2` | number of web workers to spawn
| | |
54 | workerScript | `gif.worker.js` | url to load worker script from
| | |
55 | background | `#fff` | background color where source image is transp
arent | | |
56 | width | `null` | output image width
| | |
57 | height | `null` | output image height
| | |
58 | transparent | `null` | transparent hex color, `0x00FF00` = green
| | |
59 | |
60 If width or height is `null` image size will be deteremined by first frame added
. | |
61 | |
62 ### addFrame options | |
63 | |
64 | Name | Default | Description
| | |
65 | -------------|-----------------|----------------------------------------------
------| | |
66 | delay | `500` | frame delay
| | |
67 | copy | `false` | copy the pixel data
| | |
68 | |
69 ## Wishlist | |
70 | |
71 If you want to contribute, here's some stuff that would be nice to have. | |
72 | |
73 * Tests | |
74 * Fallbacks and polyfills for old browsers | |
75 * Dithering! | |
76 | |
77 ## Acknowledgements | |
78 | |
79 gif.js is based on: | |
80 | |
81 * [Kevin Weiner's Animated gif encoder classes](http://www.fmsware.com/stuff/gi
f.html) | |
82 * [Neural-Net color quantization algorithm by Anthony Dekker](http://members.oz
email.com.au/~dekker/NEUQUANT.HTML) | |
83 * [Thibault Imbert's as3gif](https://code.google.com/p/as3gif/) | |
84 | |
85 ## License | |
86 | |
87 The MIT License (MIT) | |
88 | |
89 Copyright (c) 2013 Johan Nordberg | |
90 | |
91 Permission is hereby granted, free of charge, to any person obtaining a copy | |
92 of this software and associated documentation files (the "Software"), to deal | |
93 in the Software without restriction, including without limitation the rights | |
94 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
95 copies of the Software, and to permit persons to whom the Software is | |
96 furnished to do so, subject to the following conditions: | |
97 | |
98 The above copyright notice and this permission notice shall be included in | |
99 all copies or substantial portions of the Software. | |
100 | |
101 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
102 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
103 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
104 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
105 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
106 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
107 THE SOFTWARE. | |
OLD | NEW |