Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30eb99b

Browse files
committed
Improve docs and document typed array argument
1 parent 0217e79 commit 30eb99b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,39 @@ $ npm install jpeg-js
1616

1717
### Decoding JPEGs
1818

19+
Will decode a buffer or typed array into a `Buffer`;
20+
1921
``` js
22+
var jpeg = require('jpeg-js');
2023
var jpegData = fs.readFileSync('grumpycat.jpg');
2124
var rawImageData = jpeg.decode(jpegData);
25+
console.log(jpegData.data);
26+
/*
27+
{ width: 320,
28+
height: 180,
29+
data: <Buffer 5b 40 29 ff 59 3e 29 ff 54 3c 26 ff 55 3a 27 ff 5a 3e 2f ff 5c 3c 31 ff 58 35 2d ff 5b 36 2f ff 55 35 32 ff 5a 3a 37 ff 54 36 32 ff 4b 32 2c ff 4b 36 ... > }
30+
*/
31+
```
32+
33+
To decode directly into a `Uint8Array`, pass `true` as the second argument to
34+
`decode`:
35+
36+
``` js
37+
var jpeg = require('jpeg-js');
38+
var jpegData = fs.readFileSync('grumpycat.jpg');
39+
var rawImageData = jpeg.decode(jpegData, true); // return as Uint8Array
40+
console.log(jpegData.data);
41+
/*
42+
{ width: 320,
43+
height: 180,
44+
data: { '0': 91, '1': 64, ... } } // typed array
45+
*/
2246
```
2347

2448
### Encoding JPEGs
2549

2650
``` js
51+
var jpeg = require('jpeg-js');
2752
var width = 320, height = 180;
2853
var frameData = new Buffer(width * height * 4);
2954
var i = 0;
@@ -39,6 +64,10 @@ var rawImageData = {
3964
height: height
4065
};
4166
var jpegImageData = jpeg.encode(rawImageData, 50);
67+
console.log(jpegImageData);
68+
/*
69+
<Buffer 5b 40 29 ff 59 3e 29 ff 54 3c 26 ff 55 3a 27 ff 5a 3e 2f ff 5c 3c 31 ff 58 35 2d ff 5b 36 2f ff 55 35 32 ff 5a 3a 37 ff 54 36 32 ff 4b 32 2c ff 4b 36 ... >
70+
*/
4271
```
4372

4473
## License

0 commit comments

Comments
 (0)