UNPKG

26.5 kBMarkdownView Raw
1# node-canvas
2
3[![Build Status](https://travis-ci.org/Automattic/node-canvas.svg?branch=master)](https://travis-ci.org/Automattic/node-canvas)
4[![NPM version](https://badge.fury.io/js/canvas.svg)](http://badge.fury.io/js/canvas)
5
6node-canvas is a [Cairo](http://cairographics.org/)-backed Canvas implementation for [Node.js](http://nodejs.org).
7
8## Installation
9
10```bash
11$ npm install canvas
12```
13
14By default, binaries for macOS, Linux and Windows will be downloaded. If you want to build from source, use `npm install --build-from-source` and see the **Compiling** section below.
15
16The minimum version of Node.js required is **6.0.0**.
17
18### Compiling
19
20If you don't have a supported OS or processor architecture, or you use `--build-from-source`, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.
21
22For detailed installation information, see the [wiki](https://github.com/Automattic/node-canvas/wiki/_pages). One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.
23
24OS | Command
25----- | -----
26OS X | Using [Homebrew](https://brew.sh/):<br/>`brew install pkg-config cairo pango libpng jpeg giflib librsvg`
27Ubuntu | `sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev`
28Fedora | `sudo yum install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel`
29Solaris | `pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto`
30OpenBSD | `doas pkg_add cairo pango png jpeg giflib`
31Windows | See the [wiki](https://github.com/Automattic/node-canvas/wiki/Installation:-Windows)
32Others | See the [wiki](https://github.com/Automattic/node-canvas/wiki)
33
34**Mac OS X v10.11+:** If you have recently updated to Mac OS X v10.11+ and are experiencing trouble when compiling, run the following command: `xcode-select --install`. Read more about the problem [on Stack Overflow](http://stackoverflow.com/a/32929012/148072).
35If you have xcode 10.0 or higher installed, in order to build from source you need NPM 6.4.1 or higher.
36
37## Quick Example
38
39```javascript
40const { createCanvas, loadImage } = require('canvas')
41const canvas = createCanvas(200, 200)
42const ctx = canvas.getContext('2d')
43
44// Write "Awesome!"
45ctx.font = '30px Impact'
46ctx.rotate(0.1)
47ctx.fillText('Awesome!', 50, 100)
48
49// Draw line under text
50var text = ctx.measureText('Awesome!')
51ctx.strokeStyle = 'rgba(0,0,0,0.5)'
52ctx.beginPath()
53ctx.lineTo(50, 102)
54ctx.lineTo(50 + text.width, 102)
55ctx.stroke()
56
57// Draw cat with lime helmet
58loadImage('examples/images/lime-cat.jpg').then((image) => {
59 ctx.drawImage(image, 50, 0, 70, 70)
60
61 console.log('<img src="' + canvas.toDataURL() + '" />')
62})
63```
64
65## Upgrading from 2.x
66
67See the [changelog](https://github.com/Automattic/node-canvas/blob/master/CHANGELOG.md) for a guide to upgrading from 1.x to 2.x.
68
69For version 1.x documentation, see [the v1.x branch](https://github.com/Automattic/node-canvas/tree/v1.x).
70
71## Documentation
72
73This project is an implementation of the Web Canvas API and implements that API as closely as possible. For API documentation, please visit [Mozilla Web Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API). (See [Compatibility Status](https://github.com/Automattic/node-canvas/wiki/Compatibility-Status) for the current API compliance.) All utility methods and non-standard APIs are documented below.
74
75### Utility methods
76
77* [createCanvas()](#createcanvas)
78* [createImageData()](#createimagedata)
79* [loadImage()](#loadimage)
80* [registerFont()](#registerfont)
81
82### Non-standard APIs
83
84* [Image#src](#imagesrc)
85* [Image#dataMode](#imagedatamode)
86* [Canvas#toBuffer()](#canvastobuffer)
87* [Canvas#createPNGStream()](#canvascreatepngstream)
88* [Canvas#createJPEGStream()](#canvascreatejpegstream)
89* [Canvas#createPDFStream()](#canvascreatepdfstream)
90* [Canvas#toDataURL()](#canvastodataurl)
91* [CanvasRenderingContext2D#patternQuality](#canvasrenderingcontext2dpatternquality)
92* [CanvasRenderingContext2D#quality](#canvasrenderingcontext2dquality)
93* [CanvasRenderingContext2D#textDrawingMode](#canvasrenderingcontext2dtextdrawingmode)
94* [CanvasRenderingContext2D#globalCompositeOperator = 'saturate'](#canvasrenderingcontext2dglobalcompositeoperator--saturate)
95* [CanvasRenderingContext2D#antialias](#canvasrenderingcontext2dantialias)
96
97### createCanvas()
98
99> ```ts
100> createCanvas(width: number, height: number, type?: 'PDF'|'SVG') => Canvas
101> ```
102
103Creates a Canvas instance. This method works in both Node.js and Web browsers, where there is no Canvas constructor. (See `browser.js` for the implementation that runs in browsers.)
104
105```js
106const { createCanvas } = require('canvas')
107const mycanvas = createCanvas(200, 200)
108const myPDFcanvas = createCanvas(600, 800, 'pdf') // see "PDF Support" section
109```
110
111### createImageData()
112
113> ```ts
114> createImageData(width: number, height: number) => ImageData
115> createImageData(data: Uint8ClampedArray, width: number, height?: number) => ImageData
116> // for alternative pixel formats:
117> createImageData(data: Uint16Array, width: number, height?: number) => ImageData
118> ```
119
120Creates an ImageData instance. This method works in both Node.js and Web browsers.
121
122```js
123const { createImageData } = require('canvas')
124const width = 20, height = 20
125const arraySize = width * height * 4
126const mydata = createImageData(new Uint8ClampedArray(arraySize), width)
127```
128
129### loadImage()
130
131> ```ts
132> loadImage() => Promise<Image>
133> ```
134
135Convenience method for loading images. This method works in both Node.js and Web browsers.
136
137```js
138const { loadImage } = require('canvas')
139const myimg = loadImage('http://server.com/image.png')
140
141myimg.then(() => {
142 // do something with image
143}).catch(err => {
144 console.log('oh no!', err)
145})
146
147// or with async/await:
148const myimg = await loadImage('http://server.com/image.png')
149// do something with image
150```
151
152### registerFont()
153
154> ```ts
155> registerFont(path: string, { family: string, weight?: string, style?: string }) => void
156> ```
157
158To use a font file that is not installed as a system font, use `registerFont()` to register the font with Canvas. *This must be done before the Canvas is created.*
159
160```js
161const { registerFont, createCanvas } = require('canvas')
162registerFont('comicsans.ttf', { family: 'Comic Sans' })
163
164const canvas = createCanvas(500, 500)
165const ctx = canvas.getContext('2d')
166
167ctx.font = '12px "Comic Sans"'
168ctx.fillText('Everyone hates this font :(', 250, 10)
169```
170
171The second argument is an object with properties that resemble the CSS properties that are specified in `@font-face` rules. You must specify at least `family`. `weight`, and `style` are optional and default to `'normal'`.
172
173### Image#src
174
175> ```ts
176> img.src: string|Buffer
177> ```
178
179As in browsers, `img.src` can be set to a `data:` URI or a remote URL. In addition, node-canvas allows setting `src` to a local file path or `Buffer` instance.
180
181```javascript
182const { Image } = require('canvas')
183
184// From a buffer:
185fs.readFile('images/squid.png', (err, squid) => {
186 if (err) throw err
187 const img = new Image()
188 img.onload = () => ctx.drawImage(img, 0, 0)
189 img.onerror = err => { throw err }
190 img.src = squid
191})
192
193// From a local file path:
194const img = new Image()
195img.onload = () => ctx.drawImage(img, 0, 0)
196img.onerror = err => { throw err }
197img.src = 'images/squid.png'
198
199// From a remote URL:
200img.src = 'http://picsum.photos/200/300'
201// ... as above
202
203// From a `data:` URI:
204img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
205// ... as above
206```
207
208*Note: In some cases, `img.src=` is currently synchronous. However, you should always use `img.onload` and `img.onerror`, as we intend to make `img.src=` always asynchronous as it is in browsers. See https://github.com/Automattic/node-canvas/issues/1007.*
209
210### Image#dataMode
211
212> ```ts
213> img.dataMode: number
214> ```
215
216Applies to JPEG images drawn to PDF canvases only.
217
218Setting `img.dataMode = Image.MODE_MIME` or `Image.MODE_MIME|Image.MODE_IMAGE` enables MIME data tracking of images. When MIME data is tracked, PDF canvases can embed JPEGs directly into the output, rather than re-encoding into PNG. This can drastically reduce filesize and speed up rendering.
219
220```javascript
221const { Image, createCanvas } = require('canvas')
222const canvas = createCanvas(w, h, 'pdf')
223const img = new Image()
224img.dataMode = Image.MODE_IMAGE // Only image data tracked
225img.dataMode = Image.MODE_MIME // Only mime data tracked
226img.dataMode = Image.MODE_MIME | Image.MODE_IMAGE // Both are tracked
227```
228
229If working with a non-PDF canvas, image data *must* be tracked; otherwise the output will be junk.
230
231Enabling mime data tracking has no benefits (only a slow down) unless you are generating a PDF.
232
233### Canvas#toBuffer()
234
235> ```ts
236> canvas.toBuffer((err: Error|null, result: Buffer) => void, mimeType?: string, config?: any) => void
237> canvas.toBuffer(mimeType?: string, config?: any) => Buffer
238> ```
239
240Creates a [`Buffer`](https://nodejs.org/api/buffer.html) object representing the image contained in the canvas.
241
242* **callback** If provided, the buffer will be provided in the callback instead of being returned by the function. Invoked with an error as the first argument if encoding failed, or the resulting buffer as the second argument if it succeeded. Not supported for mimeType `raw` or for PDF or SVG canvases.
243* **mimeType** A string indicating the image format. Valid options are `image/png`, `image/jpeg` (if node-canvas was built with JPEG support), `raw` (unencoded data in BGRA order on little-endian (most) systems, ARGB on big-endian systems; top-to-bottom), `application/pdf` (for PDF canvases) and `image/svg+xml` (for SVG canvases). Defaults to `image/png` for image canvases, or the corresponding type for PDF or SVG canvas.
244* **config**
245 * For `image/jpeg`, an object specifying the quality (0 to 1), if progressive compression should be used and/or if chroma subsampling should be used: `{quality: 0.75, progressive: false, chromaSubsampling: true}`. All properties are optional.
246
247 * For `image/png`, an object specifying the ZLIB compression level (between 0 and 9), the compression filter(s), the palette (indexed PNGs only), the the background palette index (indexed PNGs only) and/or the resolution (ppi): `{compressionLevel: 6, filters: canvas.PNG_ALL_FILTERS, palette: undefined, backgroundIndex: 0, resolution: undefined}`. All properties are optional.
248
249 Note that the PNG format encodes the resolution in pixels per meter, so if you specify `96`, the file will encode 3780 ppm (~96.01 ppi). The resolution is undefined by default to match common browser behavior.
250
251 * For `application/pdf`, an object specifying optional document metadata: `{title: string, author: string, subject: string, keywords: string, creator: string, creationDate: Date, modDate: Date}`. All properties are optional and default to `undefined`, except for `creationDate`, which defaults to the current date. *Adding metadata requires Cairo 1.16.0 or later.*
252
253 For a description of these properties, see page 550 of [PDF 32000-1:2008](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf).
254
255 Note that there is no standard separator for `keywords`. A space is recommended because it is in common use by other applications, and Cairo will enclose the list of keywords in quotes if a comma or semicolon is used.
256
257**Return value**
258
259If no callback is provided, a [`Buffer`](https://nodejs.org/api/buffer.html). If a callback is provided, none.
260
261#### Examples
262
263```js
264// Default: buf contains a PNG-encoded image
265const buf = canvas.toBuffer()
266
267// PNG-encoded, zlib compression level 3 for faster compression but bigger files, no filtering
268const buf2 = canvas.toBuffer('image/png', { compressionLevel: 3, filters: canvas.PNG_FILTER_NONE })
269
270// JPEG-encoded, 50% quality
271const buf3 = canvas.toBuffer('image/jpeg', { quality: 0.5 })
272
273// Asynchronous PNG
274canvas.toBuffer((err, buf) => {
275 if (err) throw err // encoding failed
276 // buf is PNG-encoded image
277})
278
279canvas.toBuffer((err, buf) => {
280 if (err) throw err // encoding failed
281 // buf is JPEG-encoded image at 95% quality
282}, 'image/jpeg', { quality: 0.95 })
283
284// BGRA pixel values, native-endian
285const buf4 = canvas.toBuffer('raw')
286const { stride, width } = canvas
287// In memory, this is `canvas.height * canvas.stride` bytes long.
288// The top row of pixels, in BGRA order on little-endian hardware,
289// left-to-right, is:
290const topPixelsBGRALeftToRight = buf4.slice(0, width * 4)
291// And the third row is:
292const row3 = buf4.slice(2 * stride, 2 * stride + width * 4)
293
294// SVG and PDF canvases
295const myCanvas = createCanvas(w, h, 'pdf')
296myCanvas.toBuffer() // returns a buffer containing a PDF-encoded canvas
297// With optional metadata:
298myCanvas.toBuffer('application/pdf', {
299 title: 'my picture',
300 keywords: 'node.js demo cairo',
301 creationDate: new Date()
302})
303```
304
305### Canvas#createPNGStream()
306
307> ```ts
308> canvas.createPNGStream(config?: any) => ReadableStream
309> ```
310
311Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits PNG-encoded data.
312
313* `config` An object specifying the ZLIB compression level (between 0 and 9), the compression filter(s), the palette (indexed PNGs only) and/or the background palette index (indexed PNGs only): `{compressionLevel: 6, filters: canvas.PNG_ALL_FILTERS, palette: undefined, backgroundIndex: 0, resolution: undefined}`. All properties are optional.
314
315#### Examples
316
317```javascript
318const fs = require('fs')
319const out = fs.createWriteStream(__dirname + '/test.png')
320const stream = canvas.createPNGStream()
321stream.pipe(out)
322out.on('finish', () => console.log('The PNG file was created.'))
323```
324
325To encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object:
326
327```js
328const palette = new Uint8ClampedArray([
329 //r g b a
330 0, 50, 50, 255, // index 1
331 10, 90, 90, 255, // index 2
332 127, 127, 255, 255
333 // ...
334])
335canvas.createPNGStream({
336 palette: palette,
337 backgroundIndex: 0 // optional, defaults to 0
338})
339```
340
341### Canvas#createJPEGStream()
342
343> ```ts
344> canvas.createJPEGStream(config?: any) => ReadableStream
345> ```
346
347Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits JPEG-encoded data.
348
349*Note: At the moment, `createJPEGStream()` is synchronous under the hood. That is, it runs in the main thread, not in the libuv threadpool.*
350
351* `config` an object specifying the quality (0 to 1), if progressive compression should be used and/or if chroma subsampling should be used: `{quality: 0.75, progressive: false, chromaSubsampling: true}`. All properties are optional.
352
353#### Examples
354
355```javascript
356const fs = require('fs')
357const out = fs.createWriteStream(__dirname + '/test.jpeg')
358const stream = canvas.createJPEGStream()
359stream.pipe(out)
360out.on('finish', () => console.log('The JPEG file was created.'))
361
362// Disable 2x2 chromaSubsampling for deeper colors and use a higher quality
363const stream = canvas.createJPEGStream({
364 quality: 0.95,
365 chromaSubsampling: false
366})
367```
368
369### Canvas#createPDFStream()
370
371> ```ts
372> canvas.createPDFStream(config?: any) => ReadableStream
373> ```
374
375* `config` an object specifying optional document metadata: `{title: string, author: string, subject: string, keywords: string, creator: string, creationDate: Date, modDate: Date}`. See `toBuffer()` for more information. *Adding metadata requires Cairo 1.16.0 or later.*
376
377Applies to PDF canvases only. Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits the encoded PDF. `canvas.toBuffer()` also produces an encoded PDF, but `createPDFStream()` can be used to reduce memory usage.
378
379### Canvas#toDataURL()
380
381This is a standard API, but several non-standard calls are supported. The full list of supported calls is:
382
383```js
384dataUrl = canvas.toDataURL() // defaults to PNG
385dataUrl = canvas.toDataURL('image/png')
386dataUrl = canvas.toDataURL('image/jpeg')
387dataUrl = canvas.toDataURL('image/jpeg', quality) // quality from 0 to 1
388canvas.toDataURL((err, png) => { }) // defaults to PNG
389canvas.toDataURL('image/png', (err, png) => { })
390canvas.toDataURL('image/jpeg', (err, jpeg) => { }) // sync JPEG is not supported
391canvas.toDataURL('image/jpeg', {...opts}, (err, jpeg) => { }) // see Canvas#createJPEGStream for valid options
392canvas.toDataURL('image/jpeg', quality, (err, jpeg) => { }) // spec-following; quality from 0 to 1
393```
394
395### CanvasRenderingContext2D#patternQuality
396
397> ```ts
398> context.patternQuality: 'fast'|'good'|'best'|'nearest'|'bilinear'
399> ```
400
401Defaults to `'good'`. Affects pattern (gradient, image, etc.) rendering quality.
402
403### CanvasRenderingContext2D#quality
404
405> ```ts
406> context.quality: 'fast'|'good'|'best'|'nearest'|'bilinear'
407> ```
408
409Defaults to `'good'`. Like `patternQuality`, but applies to transformations affecting more than just patterns.
410
411### CanvasRenderingContext2D#textDrawingMode
412
413> ```ts
414> context.textDrawingMode: 'path'|'glyph'
415> ```
416
417Defaults to `'path'`. The effect depends on the canvas type:
418
419* **Standard (image)** `glyph` and `path` both result in rasterized text. Glyph mode is faster than `path`, but may result in lower-quality text, especially when rotated or translated.
420
421* **PDF** `glyph` will embed text instead of paths into the PDF. This is faster to encode, faster to open with PDF viewers, yields a smaller file size and makes the text selectable. The subset of the font needed to render the glyphs will be embedded in the PDF. This is usually the mode you want to use with PDF canvases.
422
423* **SVG** `glyph` does *not* cause `<text>` elements to be produced as one might expect ([cairo bug](https://gitlab.freedesktop.org/cairo/cairo/issues/253)). Rather, `glyph` will create a `<defs>` section with a `<symbol>` for each glyph, then those glyphs be reused via `<use>` elements. `path` mode creates a `<path>` element for each text string. `glyph` mode is faster and yields a smaller file size.
424
425In `glyph` mode, `ctx.strokeText()` and `ctx.fillText()` behave the same (aside from using the stroke and fill style, respectively).
426
427This property is tracked as part of the canvas state in save/restore.
428
429### CanvasRenderingContext2D#globalCompositeOperation = 'saturate'
430
431In addition to all of the standard global composite operations defined by the Canvas specification, the ['saturate'](https://www.cairographics.org/operators/#saturate) operation is also available.
432
433### CanvasRenderingContext2D#antialias
434
435> ```ts
436> context.antialias: 'default'|'none'|'gray'|'subpixel'
437> ```
438
439Sets the anti-aliasing mode.
440
441## PDF Output Support
442
443node-canvas can create PDF documents instead of images. The canvas type must be set when creating the canvas as follows:
444
445```js
446const canvas = createCanvas(200, 500, 'pdf')
447```
448
449An additional method `.addPage()` is then available to create multiple page PDFs:
450
451```js
452// On first page
453ctx.font = '22px Helvetica'
454ctx.fillText('Hello World', 50, 80)
455
456ctx.addPage()
457// Now on second page
458ctx.font = '22px Helvetica'
459ctx.fillText('Hello World 2', 50, 80)
460
461canvas.toBuffer() // returns a PDF file
462canvas.createPDFStream() // returns a ReadableStream that emits a PDF
463// With optional document metadata (requires Cairo 1.16.0):
464canvas.toBuffer('application/pdf', {
465 title: 'my picture',
466 keywords: 'node.js demo cairo',
467 creationDate: new Date()
468})
469```
470
471It is also possible to create pages with different sizes by passing `width` and `height` to the `.addPage()` method:
472
473```js
474ctx.font = '22px Helvetica'
475ctx.fillText('Hello World', 50, 80)
476ctx.addPage(400, 800)
477
478ctx.fillText('Hello World 2', 50, 80)
479```
480
481See also:
482
483* [Image#dataMode](#imagedatamode) for embedding JPEGs in PDFs
484* [Canvas#createPDFStream()](#canvascreatepdfstream) for creating PDF streams
485* [CanvasRenderingContext2D#textDrawingMode](#canvasrenderingcontext2dtextdrawingmode)
486 for embedding text instead of paths
487
488## SVG Output Support
489
490node-canvas can create SVG documents instead of images. The canvas type must be set when creating the canvas as follows:
491
492```js
493const canvas = createCanvas(200, 500, 'svg')
494// Use the normal primitives.
495fs.writeFileSync('out.svg', canvas.toBuffer())
496```
497
498## SVG Image Support
499
500If librsvg is available when node-canvas is installed, node-canvas can render SVG images to your canvas context. This currently works by rasterizing the SVG image (i.e. drawing an SVG image to an SVG canvas will not preserve the SVG data).
501
502```js
503const img = new Image()
504img.onload = () => ctx.drawImage(img, 0, 0)
505img.onerror = err => { throw err }
506img.src = './example.svg'
507```
508
509## Image pixel formats (experimental)
510
511node-canvas has experimental support for additional pixel formats, roughly following the [Canvas color space proposal](https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md).
512
513```js
514const canvas = createCanvas(200, 200)
515const ctx = canvas.getContext('2d', { pixelFormat: 'A8' })
516```
517
518By default, canvases are created in the `RGBA32` format, which corresponds to the native HTML Canvas behavior. Each pixel is 32 bits. The JavaScript APIs that involve pixel data (`getImageData`, `putImageData`) store the colors in the order {red, green, blue, alpha} without alpha pre-multiplication. (The C++ API stores the colors in the order {alpha, red, green, blue} in native-[endian](https://en.wikipedia.org/wiki/Endianness) ordering, with alpha pre-multiplication.)
519
520These additional pixel formats have experimental support:
521
522* `RGB24` Like `RGBA32`, but the 8 alpha bits are always opaque. This format is always used if the `alpha` context attribute is set to false (i.e. `canvas.getContext('2d', {alpha: false})`). This format can be faster than `RGBA32` because transparency does not need to be calculated.
523* `A8` Each pixel is 8 bits. This format can either be used for creating grayscale images (treating each byte as an alpha value), or for creating indexed PNGs (treating each byte as a palette index) (see [the example using alpha values with `fillStyle`](examples/indexed-png-alpha.js) and [the example using `imageData`](examples/indexed-png-image-data.js)).
524* `RGB16_565` Each pixel is 16 bits, with red in the upper 5 bits, green in the middle 6 bits, and blue in the lower 5 bits, in native platform endianness. Some hardware devices and frame buffers use this format. Note that PNG does not support this format; when creating a PNG, the image will be converted to 24-bit RGB. This format is thus suboptimal for generating PNGs. `ImageData` instances for this mode use a `Uint16Array` instead of a `Uint8ClampedArray`.
525* `A1` Each pixel is 1 bit, and pixels are packed together into 32-bit quantities. The ordering of the bits matches the endianness of the
526 platform: on a little-endian machine, the first pixel is the least-significant bit. This format can be used for creating single-color images. *Support for this format is incomplete, see note below.*
527* `RGB30` Each pixel is 30 bits, with red in the upper 10, green in the middle 10, and blue in the lower 10. (Requires Cairo 1.12 or later.) *Support for this format is incomplete, see note below.*
528
529Notes and caveats:
530
531* Using a non-default format can affect the behavior of APIs that involve pixel data:
532
533 * `context2d.createImageData` The size of the array returned depends on the number of bit per pixel for the underlying image data format, per the above descriptions.
534 * `context2d.getImageData` The format of the array returned depends on the underlying image mode, per the above descriptions. Be aware of platform endianness, which can be determined using node.js's [`os.endianness()`](https://nodejs.org/api/os.html#os_os_endianness)
535 function.
536 * `context2d.putImageData` As above.
537
538* `A1` and `RGB30` do not yet support `getImageData` or `putImageData`. Have a use case and/or opinion on working with these formats? Open an issue and let us know! (See #935.)
539
540* `A1`, `A8`, `RGB30` and `RGB16_565` with shadow blurs may crash or not render properly.
541
542* The `ImageData(width, height)` and `ImageData(Uint8ClampedArray, width)` constructors assume 4 bytes per pixel. To create an `ImageData` instance with a different number of bytes per pixel, use `new ImageData(new Uint8ClampedArray(size), width, height)` or `new ImageData(new Uint16ClampedArray(size), width, height)`.
543
544## Testing
545
546First make sure you've built the latest version. Get all the deps you need (see [compiling](#compiling) above), and run:
547
548```
549npm install --build-from-source
550```
551
552For visual tests: `npm run test-server` and point your browser to http://localhost:4000.
553
554For unit tests: `npm run test`.
555
556## Benchmarks
557
558Benchmarks live in the `benchmarks` directory.
559
560## Examples
561
562Examples line in the `examples` directory. Most produce a png image of the same name, and others such as *live-clock.js* launch an HTTP server to be viewed in the browser.
563
564## Original Authors
565
566 - TJ Holowaychuk ([tj](http://github.com/tj))
567 - Nathan Rajlich ([TooTallNate](http://github.com/TooTallNate))
568 - Rod Vagg ([rvagg](http://github.com/rvagg))
569 - Juriy Zaytsev ([kangax](http://github.com/kangax))
570
571## License
572
573### node-canvas
574
575(The MIT License)
576
577Copyright (c) 2010 LearnBoost, and contributors &lt;dev@learnboost.com&gt;
578
579Copyright (c) 2014 Automattic, Inc and contributors &lt;dev@automattic.com&gt;
580
581Permission is hereby granted, free of charge, to any person obtaining a copy of
582this software and associated documentation files (the 'Software'), to deal in
583the Software without restriction, including without limitation the rights to
584use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
585the Software, and to permit persons to whom the Software is furnished to do so,
586subject to the following conditions:
587
588The above copyright notice and this permission notice shall be included in all
589copies or substantial portions of the Software.
590
591THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
592IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
593FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
594COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
595IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
596CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
597
598### BMP parser
599
600See [license](src/bmp/LICENSE.md)