{"name":"canvas","version":"2.0.0-alpha.12","keywords":["canvas","graphic","graphics","pixman","cairo","image","images","pdf"],"author":{"name":"TJ Holowaychuk","email":"tj@learnboost.com"},"license":"MIT","_id":"canvas@2.0.0-alpha.12","maintainers":[{"name":"domenic","email":"d@domenic.me"},{"name":"kangax","email":"kangax@gmail.com"},{"name":"linusu","email":"linus@folkdatorn.se"},{"name":"rauchg","email":"rauchg@gmail.com"},{"name":"tjholowaychuk","email":"tj@vision-media.ca"},{"name":"tootallnate","email":"nathan@tootallnate.net"}],"contributors":[{"name":"Nathan Rajlich","email":"nathan@tootallnate.net"},{"name":"Rod Vagg","email":"r@va.gg"},{"name":"Juriy Zaytsev","email":"kangax@gmail.com"}],"homepage":"https://github.com/Automattic/node-canvas","bugs":{"url":"https://github.com/Automattic/node-canvas/issues"},"dist":{"shasum":"01ae4efc037b982be561b17f3c9707f95c544a90","tarball":"http://registry-npm.ywwl.com/canvas/download/canvas-2.0.0-alpha.12.tgz","fileCount":58,"integrity":"sha512-ra8lev8agfQmiowJ2xJCVKA3L79RqwNcd2XboiHYWfRKlVk29NLye0ozK8/4iUHt/TIMe+knQoCEI6Dtlwep8w==","signatures":[{"sig":"MEYCIQCsnkTDFGcV5A+p08RXaWpD1o9VDacB2QR7fhmEhdHEgAIhAIlkCSskNfnjIWEh6sG3rWFFs/HRzq13o/yIrygA5W/V","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":305606,"size":76434,"noattachment":false,"key":"/canvas/-/canvas-2.0.0-alpha.12.tgz"},"main":"index.js","binary":{"host":"https://github.com/node-gfx/node-canvas-prebuilt/releases/download/","module_name":"canvas-prebuilt","module_path":"build/Release","remote_path":"v{version}"},"readme":"# node-canvas\n\n-----\n\n## This is the documentation for version 2.0.0-alpha\nAlpha versions of 2.0 can be installed using `npm install canvas@next`.\n\n**For version 1.x documentation, see [the v1.x branch](https://github.com/Automattic/node-canvas/tree/v1.x)**\n\n-----\n\n### Canvas graphics API backed by Cairo\n[![Build Status](https://travis-ci.org/Automattic/node-canvas.svg?branch=master)](https://travis-ci.org/Automattic/node-canvas)\n[![NPM version](https://badge.fury.io/js/canvas.svg)](http://badge.fury.io/js/canvas)\n\n  node-canvas is a [Cairo](http://cairographics.org/) backed Canvas implementation for [NodeJS](http://nodejs.org).\n\n## Authors\n\n  - TJ Holowaychuk ([tj](http://github.com/tj))\n  - Nathan Rajlich ([TooTallNate](http://github.com/TooTallNate))\n  - Rod Vagg ([rvagg](http://github.com/rvagg))\n  - Juriy Zaytsev ([kangax](http://github.com/kangax))\n\n## Installation\n\n```bash\n$ npm install canvas\n```\n\nBy default, binaries for macOS, Linux and Windows will be downloaded. If you want to build from source, use `npm install --build-from-source`.\n\nCurrently the minimum version of node required is __4.0.0__\n\n### Compiling\n\nIf you don't have a supported OS or processor architecture, or you use `--build-from-source`, the module will be compiled on your system. Unless previously installed you'll _need_ __Cairo__ and __Pango__. For system-specific installation view the [Wiki](https://github.com/Automattic/node-canvas/wiki/_pages).\n\nYou can quickly install the dependencies by using the command for your OS:\n\nOS | Command\n----- | -----\nOS X | Using [Homebrew](https://brew.sh/):<br/>`brew install pkg-config cairo pango libpng jpeg giflib`<br/><br/>Using [MacPorts](https://www.macports.org/):<br/>`port install pkgconfig cairo pango libpng jpeg giflib`\nUbuntu | `sudo apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++`\nFedora | `sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel`\nSolaris | `pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto`\nWindows | [Instructions on our wiki](https://github.com/Automattic/node-canvas/wiki/Installation---Windows)\n\n**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).\n\n## Screencasts\n\n  - [Introduction](http://screenr.com/CTk)\n\n## Example\n\n```javascript\nconst { createCanvas, loadImage } = require('canvas')\nconst canvas = createCanvas(200, 200)\nconst ctx = canvas.getContext('2d')\n\n// Write \"Awesome!\"\nctx.font = '30px Impact'\nctx.rotate(0.1)\nctx.fillText('Awesome!', 50, 100)\n\n// Draw line under text\nvar text = ctx.measureText('Awesome!')\nctx.strokeStyle = 'rgba(0,0,0,0.5)'\nctx.beginPath()\nctx.lineTo(50, 102)\nctx.lineTo(50 + text.width, 102)\nctx.stroke()\n\n// Draw cat with lime helmet\nloadImage('examples/images/lime-cat.jpg').then((image) => {\n  ctx.drawImage(image, 50, 0, 70, 70)\n\n  console.log('<img src=\"' + canvas.toDataURL() + '\" />')\n})\n```\n\n## Non-Standard API\n\n node-canvas extends the canvas API to provide interfacing with node, for example streaming PNG data, converting to a `Buffer` instance, etc. Among the interfacing API, in some cases the drawing API has been extended for SSJS image manipulation / creation usage, however keep in mind these additions may fail to render properly within browsers.\n\n### Image#src=Buffer\n\n node-canvas adds `Image#src=Buffer` support, allowing you to read images from disc, redis, etc and apply them via `ctx.drawImage()`. Below we draw scaled down squid png by reading it from the disk with node's I/O.\n\n```javascript\nconst { Image } = require('canvas');\nfs.readFile(__dirname + '/images/squid.png', function(err, squid){\n  if (err) throw err;\n  img = new Image;\n  img.src = squid;\n  ctx.drawImage(img, 0, 0, img.width / 4, img.height / 4);\n});\n```\n\n Below is an example of a canvas drawing it-self as the source several time:\n\n```javascript\nconst { Image } = require('canvas');\nvar img = new Image;\nimg.src = canvas.toBuffer();\nctx.drawImage(img, 0, 0, 50, 50);\nctx.drawImage(img, 50, 0, 50, 50);\nctx.drawImage(img, 100, 0, 50, 50);\n```\n\n### Image#dataMode\n\nnode-canvas adds `Image#dataMode` support, which can be used to opt-in to mime data tracking of images (currently only JPEGs).\n\nWhen mime data is tracked, in PDF mode JPEGs can be embedded directly into the output, rather than being re-encoded into PNG. This can drastically reduce filesize, and speed up rendering.\n\n```javascript\nconst { Image } = require('canvas');\nvar img = new Image();\nimg.dataMode = Image.MODE_IMAGE; // Only image data tracked\nimg.dataMode = Image.MODE_MIME; // Only mime data tracked\nimg.dataMode = Image.MODE_MIME | Image.MODE_IMAGE; // Both are tracked\n```\n\nIf 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.\n\n### Canvas#pngStream(options)\n\n  To create a `PNGStream` simply call `canvas.pngStream()`, and the stream will start to emit _data_ events, emitting _end_ when the data stream ends. If an exception occurs the _error_ event is emitted.\n\n```javascript\nvar fs = require('fs')\n  , out = fs.createWriteStream(__dirname + '/text.png')\n  , stream = canvas.pngStream();\n\nstream.on('data', function(chunk){\n  out.write(chunk);\n});\n\nstream.on('end', function(){\n  console.log('The PNG stream ended');\n});\n\nout.on('finish', function(){\n  console.log('The PNG file was created.');\n});\n```\n\nTo encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object:\n\n```js\nvar palette = new Uint8ClampedArray([\n  //r    g    b    a\n    0,  50,  50, 255, // index 1\n   10,  90,  90, 255, // index 2\n  127, 127, 255, 255\n  // ...\n]);\ncanvas.pngStream({\n  palette: palette,\n  backgroundIndex: 0 // optional, defaults to 0\n})\n```\n\n### Canvas#jpegStream() and Canvas#syncJPEGStream()\n\nYou can likewise create a `JPEGStream` by calling `canvas.jpegStream()` with\nsome optional parameters; functionality is otherwise identical to\n`pngStream()`. See `examples/crop.js` for an example.\n\n_Note: At the moment, `jpegStream()` is the same as `syncJPEGStream()`, both\nare synchronous_\n\n```javascript\nvar stream = canvas.jpegStream({\n    bufsize: 4096 // output buffer size in bytes, default: 4096\n  , quality: 75 // JPEG quality (0-100) default: 75\n  , progressive: false // true for progressive compression, default: false\n});\n```\n\n### Canvas#toBuffer()\n\nA call to `Canvas#toBuffer()` will return a node `Buffer` instance containing image data.\n\n```javascript\n// PNG Buffer, default settings\nvar buf = canvas.toBuffer();\n\n// PNG Buffer, zlib compression level 3 (from 0-9), faster but bigger\nvar buf2 = canvas.toBuffer(undefined, 3, canvas.PNG_FILTER_NONE);\n\n// ARGB32 Buffer, native-endian\nvar buf3 = canvas.toBuffer('raw');\nvar stride = canvas.stride;\n// In memory, this is `canvas.height * canvas.stride` bytes long.\n// The top row of pixels, in ARGB order, left-to-right, is:\nvar topPixelsARGBLeftToRight = buf3.slice(0, canvas.width * 4);\nvar row3 = buf3.slice(2 * canvas.stride, 2 * canvas.stride + canvas.width * 4);\n```\n\n### Canvas#toBuffer() async\n\nOptionally we may pass a callback function to `Canvas#toBuffer()`, and this process will be performed asynchronously, and will `callback(err, buf)`.\n\n```javascript\ncanvas.toBuffer(function(err, buf){\n\n});\n```\n\n### Canvas#toDataURL() sync and async\n\nThe following syntax patterns are supported:\n\n```javascript\nvar dataUrl = canvas.toDataURL(); // defaults to PNG\nvar dataUrl = canvas.toDataURL('image/png');\ncanvas.toDataURL(function(err, png){ }); // defaults to PNG\ncanvas.toDataURL('image/png', function(err, png){ });\ncanvas.toDataURL('image/jpeg', function(err, jpeg){ }); // sync JPEG is not supported\ncanvas.toDataURL('image/jpeg', {opts...}, function(err, jpeg){ }); // see Canvas#jpegStream for valid options\ncanvas.toDataURL('image/jpeg', quality, function(err, jpeg){ }); // spec-following; quality from 0 to 1\n```\n\n### `registerFont` for bundled fonts\n\nIt can be useful to use a custom font file if you are distributing code that uses node-canvas and a specific font. Or perhaps you are using it to do automated tests and you want the renderings to be the same across operating systems regardless of what fonts are installed.\n\nTo do that, you should use `registerFont()`.\n\n**You need to call it before the Canvas is created**\n\n```javascript\nconst { registerFont, createCanvas } = require('canvas');\nregisterFont('comicsans.ttf', {family: 'Comic Sans'});\n\nvar canvas = createCanvas(500, 500),\n  ctx = canvas.getContext('2d');\n\nctx.font = '12px \"Comic Sans\"';\nctx.fillText(250, 10, 'Everyone hates this font :(');\n```\n\nThe 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\").\n\n### CanvasRenderingContext2D#patternQuality\n\nGiven one of the values below will alter pattern (gradients, images, etc) render quality, defaults to _good_.\n\n  - fast\n  - good\n  - best\n  - nearest\n  - bilinear\n\n### CanvasRenderingContext2D#textDrawingMode\n\nCan be either `path` or `glyph`. Using `glyph` is much faster than `path` for drawing, and when using a PDF context will embed the text natively, so will be selectable and lower filesize. The downside is that cairo does not have any subpixel precision for `glyph`, so this will be noticeably lower quality for text positioning in cases such as rotated text. Also, strokeText in `glyph` will act the same as fillText, except using the stroke style for the fill.\n\nDefaults to _path_.\n\nThis property is tracked as part of the canvas state in save/restore.\n\n### CanvasRenderingContext2D#filter\n\nLike `patternQuality`, but applies to transformations effecting more than just patterns. Defaults to _good_.\n\n  - fast\n  - good\n  - best\n  - nearest\n  - bilinear\n\n### Global Composite Operations\n\nIn addition to those specified and commonly implemented by browsers, the following have been added:\n\n  - multiply\n  - screen\n  - overlay\n  - hard-light\n  - soft-light\n  - hsl-hue\n  - hsl-saturation\n  - hsl-color\n  - hsl-luminosity\n\n## Anti-Aliasing\n\n Set anti-aliasing mode\n\n - default\n - none\n - gray\n - subpixel\n\n For example:\n\n```javascript\nctx.antialias = 'none';\n```\n\n## PDF Support\n\n  Basic PDF support was added in 0.11.0. If you are building cairo from source, be sure to use `--enable-pdf=yes` for the PDF backend.\n  node-canvas must know that it is creating a PDF on initialization, using the \"pdf\" string:\n\n```js\nvar canvas = createCanvas(200, 500, 'pdf');\n```\n\n An additional method `.addPage()` is then available to create\n multiple page PDFs:\n\n```js\nctx.font = '22px Helvetica';\nctx.fillText('Hello World', 50, 80);\nctx.addPage();\n\nctx.font = '22px Helvetica';\nctx.fillText('Hello World 2', 50, 80);\nctx.addPage();\n\nctx.font = '22px Helvetica';\nctx.fillText('Hello World 3', 50, 80);\nctx.addPage();\n```\n\n## SVG Support\n\n Just like PDF support, make sure to install cairo with `--enable-svg=yes`.\n You also need to tell node-canvas that it is working on SVG upon its initialization:\n\n```js\nvar canvas = createCanvas(200, 500, 'svg');\n// Use the normal primitives.\nfs.writeFile('out.svg', canvas.toBuffer());\n```\n\n## SVG Image Support\n\nIf librsvg is on your system when node-canvas is installed, node-canvas can render SVG images within your canvas context. Note that this currently works by simply rasterizing the SVG image using librsvg.\n\n```js\nvar img = new Image;\nimg.src = './example.svg';\nctx.drawImage(img, 0, 0, 100, 100);\n```\n\n## Image pixel formats (experimental)\n\nnode-canvas has experimental support for additional pixel formats, roughly\nfollowing the [Canvas color space proposal](https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md).\n\n```js\nvar canvas = createCanvas(200, 200);\nvar ctx = canvas.getContext('2d', {pixelFormat: 'A8'});\n```\n\nBy default, canvases are created in the `RGBA32` format, which corresponds to\nthe native HTML Canvas behavior. Each pixel is 32 bits. The JavaScript APIs\nthat involve pixel data (`getImageData`, `putImageData`) store the colors in\nthe order {red, green, blue, alpha} without alpha pre-multiplication. (The C++\nAPI stores the colors in the order {alpha, red, green, blue} in native-[endian](https://en.wikipedia.org/wiki/Endianness)\nordering, with alpha pre-multiplication.)\n\nThese additional pixel formats have experimental support:\n\n* `RGB24` Like `RGBA32`, but the 8 alpha bits are always opaque. This format is\n  always used if the `alpha` context attribute is set to false (i.e.\n  `canvas.getContext('2d', {alpha: false})`). This format can be faster than\n  `RGBA32` because transparency does not need to be calculated.\n* `A8` Each pixel is 8 bits. This format can either be used for creating\n  grayscale images (treating each byte as an alpha value), or for creating\n  indexed PNGs (treating each byte as a palette index) (see [the example using\n  alpha values with `fillStyle`](examples/indexed-png-alpha.js) and [the\n  example using `imageData`](examples/indexed-png-image-data.js)).\n* `RGB16_565` Each pixel is 16 bits, with red in the upper 5 bits, green in the\n  middle 6 bits, and blue in the lower 5 bits, in native platform endianness.\n  Some hardware devices and frame buffers use this format. Note that PNG does\n  not support this format; when creating a PNG, the image will be converted to\n  24-bit RGB. This format is thus suboptimal for generating PNGs.\n  `ImageData` instances for this mode use a `Uint16Array` instead of a `Uint8ClampedArray`.\n* `A1` Each pixel is 1 bit, and pixels are packed together into 32-bit\n  quantities. The ordering of the bits matches the endianness of the\n  platform: on a little-endian machine, the first pixel is the least-\n  significant bit. This format can be used for creating single-color images.\n  *Support for this format is incomplete, see note below.*\n* `RGB30` Each pixel is 30 bits, with red in the upper 10, green\n  in the middle 10, and blue in the lower 10. (Requires Cairo 1.12 or later.)\n  *Support for this format is incomplete, see note below.*\n\nNotes and caveats:\n\n* Using a non-default format can affect the behavior of APIs that involve pixel\n  data:\n\n  * `context2d.createImageData` The size of the array returned depends on the\n    number of bit per pixel for the underlying image data format, per the above\n    descriptions.\n  * `context2d.getImageData` The format of the array returned depends on the\n    underlying image mode, per the above descriptions. Be aware of platform\n    endianness, which can be determined using node.js's [`os.endianness()`](https://nodejs.org/api/os.html#os_os_endianness)\n    function.\n  * `context2d.putImageData` As above.\n\n* `A1` and `RGB30` do not yet support `getImageData` or `putImageData`. Have a\n  use case and/or opinion on working with these formats? Open an issue and let\n  us know! (See #935.)\n\n* `A1`, `A8`, `RGB30` and `RGB16_565` with shadow blurs may crash or not render\n  properly.\n\n* The `ImageData(width, height)` and `ImageData(Uint8ClampedArray, width)`\n  constructors assume 4 bytes per pixel. To create an `ImageData` instance with\n  a different number of bytes per pixel, use\n  `new ImageData(new Uint8ClampedArray(size), width, height)` or\n  `new ImageData(new Uint16ClampedArray(size), width, height)`.\n\n## Benchmarks\n\n Although node-canvas is extremely new, and we have not even begun optimization yet it is already quite fast. For benchmarks vs other node canvas implementations view this [gist](https://gist.github.com/664922), or update the submodules and run `$ make benchmark` yourself.\n\n## Contribute\n\n Want to contribute to node-canvas? patches for features, bug fixes, documentation, examples and others are certainly welcome. Take a look at the [issue queue](https://github.com/Automattic/node-canvas/issues) for existing issues.\n\n## Examples\n\n Examples are placed in _./examples_, be sure to check them out! 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.\n\n## Testing\n\nIf you have not previously, init git submodules:\n\n    $ git submodule update --init\n\nInstall the node modules:\n\n    $ npm install\n\nBuild node-canvas:\n\n    $ node-gyp rebuild\n\nUnit tests:\n\n    $ make test\n\nVisual tests:\n\n    $ make test-server\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2010 LearnBoost, and contributors &lt;dev@learnboost.com&gt;\n\nCopyright (c) 2014 Automattic, Inc and contributors &lt;dev@automattic.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","browser":"browser.js","engines":{"node":">=4"},"gitHead":"92b192447e9b9ae98da0f801e4e34afdd1dc1ef8","scripts":{"test":"standard examples/*.js test/server.js test/public/*.js benchmark/run.js util/has_lib.js browser.js index.js && mocha test/*.test.js","install":"node-pre-gyp install --fallback-to-build","pretest":"node-gyp build","benchmark":"node benchmarks/run.js","test-server":"node test/server.js","prebenchmark":"node-gyp build","pretest-server":"node-gyp build"},"_npmUser":{"name":"linusu","email":"linus@folkdatorn.se"},"repository":{"url":"git://github.com/Automattic/node-canvas.git","type":"git"},"_npmVersion":"5.6.0","description":"Canvas graphics API backed by Cairo","directories":{},"_nodeVersion":"9.8.0","dependencies":{"nan":"^2.4.0","node-pre-gyp":"^0.9.0"},"_hasShrinkwrap":false,"readmeFilename":"Readme.md","devDependencies":{"mocha":"^3.1.2","express":"^4.14.0","standard":"^8.5.0","assert-rejects":"^0.1.1"},"_npmOperationalInternal":{"tmp":"tmp/canvas_2.0.0-alpha.12_1521747186902_0.07290251176449614","host":"s3://npm-registry-packages"},"publish_time":1521747187033,"_cnpm_publish_time":1521747187033,"dist-tags":{"latest":"3.2.3","next":"4.0.0-rc3","test":"3.0.0-rc1e"}}