You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,7 +117,7 @@ img.dataMode = Image.MODE_MIME | Image.MODE_IMAGE; // Both are tracked
117
117
118
118
If image data is not tracked, and the Image is drawn to an image rather than a PDF canvas, the output will be junk. Enabling mime data tracking has no benefits (only a slow down) unless you are generating a PDF.
119
119
120
-
### Canvas#pngStream()
120
+
### Canvas#pngStream(options)
121
121
122
122
To create a `PNGStream` simply call `canvas.pngStream()`, and the stream will start to emit _data_ events, finally emitting _end_ when finished. If an exception occurs the _error_ event is emitted.
123
123
@@ -137,6 +137,22 @@ stream.on('end', function(){
137
137
138
138
Currently _only_ sync streaming is supported, however we plan on supporting async streaming as well (of course :) ). Until then the `Canvas#toBuffer(callback)` alternative is async utilizing `eio_custom()`.
139
139
140
+
To encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object:
141
+
142
+
```js
143
+
var palette =newUint8ClampedArray([
144
+
//r g b a
145
+
0, 50, 50, 255, // index 1
146
+
10, 90, 90, 255, // index 2
147
+
127, 127, 255, 255
148
+
// ...
149
+
]);
150
+
canvas.pngStream({
151
+
palette: palette,
152
+
backgroundIndex:0// optional, defaults to 0
153
+
})
154
+
```
155
+
140
156
### Canvas#jpegStream() and Canvas#syncJPEGStream()
141
157
142
158
You can likewise create a `JPEGStream` by calling `canvas.jpegStream()` with
@@ -337,7 +353,9 @@ These additional pixel formats have experimental support:
337
353
`RGBA32` because transparency does not need to be calculated.
338
354
*`A8` Each pixel is 8 bits. This format can either be used for creating
339
355
grayscale images (treating each byte as an alpha value), or for creating
340
-
indexed PNGs (treating each byte as a palette index).
356
+
indexed PNGs (treating each byte as a palette index) (see [the example using
357
+
alpha values with `fillStyle`](examples/indexed-png-alpha.js) and [the
358
+
example using `imageData`](examples/indexed-png-image-data.js)).
341
359
*`RGB16_565` Each pixel is 16 bits, with red in the upper 5 bits, green in the
342
360
middle 6 bits, and blue in the lower 5 bits, in native platform endianness.
343
361
Some hardware devices and frame buffers use this format. Note that PNG does
@@ -369,7 +387,7 @@ Notes and caveats:
369
387
370
388
*`A1` and `RGB30` do not yet support `getImageData` or `putImageData`. Have a
371
389
use case and/or opinion on working with these formats? Open an issue and let
372
-
us know!
390
+
us know! (See #935.)
373
391
374
392
*`A1`, `A8`, `RGB30` and `RGB16_565` with shadow blurs may crash or not render
0 commit comments