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
@@ -111,7 +111,7 @@ img.dataMode = Image.MODE_MIME | Image.MODE_IMAGE; // Both are tracked
111
111
112
112
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.
113
113
114
-
### Canvas#pngStream()
114
+
### Canvas#pngStream(options)
115
115
116
116
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.
117
117
@@ -131,6 +131,22 @@ stream.on('end', function(){
131
131
132
132
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()`.
133
133
134
+
To encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object:
135
+
136
+
```js
137
+
var palette =newUint8ClampedArray([
138
+
//r g b a
139
+
0, 50, 50, 255, // index 1
140
+
10, 90, 90, 255, // index 2
141
+
127, 127, 255, 255
142
+
// ...
143
+
]);
144
+
canvas.pngStream({
145
+
palette: palette,
146
+
backgroundIndex:0// optional, defaults to 0
147
+
})
148
+
```
149
+
134
150
### Canvas#jpegStream() and Canvas#syncJPEGStream()
135
151
136
152
You can likewise create a `JPEGStream` by calling `canvas.jpegStream()` with
@@ -331,7 +347,9 @@ These additional pixel formats have experimental support:
331
347
`RGBA32` because transparency does not need to be calculated.
332
348
*`A8` Each pixel is 8 bits. This format can either be used for creating
333
349
grayscale images (treating each byte as an alpha value), or for creating
334
-
indexed PNGs (treating each byte as a palette index).
350
+
indexed PNGs (treating each byte as a palette index) (see [the example using
351
+
alpha values with `fillStyle`](examples/indexed-png-alpha.js) and [the
352
+
example using `imageData`](examples/indexed-png-image-data.js)).
335
353
*`RGB16_565` Each pixel is 16 bits, with red in the upper 5 bits, green in the
336
354
middle 6 bits, and blue in the lower 5 bits, in native platform endianness.
337
355
Some hardware devices and frame buffers use this format. Note that PNG does
@@ -363,7 +381,7 @@ Notes and caveats:
363
381
364
382
*`A1` and `RGB30` do not yet support `getImageData` or `putImageData`. Have a
365
383
use case and/or opinion on working with these formats? Open an issue and let
366
-
us know!
384
+
us know! (See #935.)
367
385
368
386
*`A1`, `A8`, `RGB30` and `RGB16_565` with shadow blurs may crash or not render
0 commit comments