{"name":"svg2png","description":"Converts SVGs to PNGs, using PhantomJS","version":"3.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me"},"license":"WTFPL","repository":{"type":"git","url":"git+https://github.com/domenic/svg2png.git"},"main":"lib/svg2png.js","bin":{"svg2png":"bin/svg2png-cli.js"},"files":["lib/","bin/"],"scripts":{"test":"mocha","rebaseline":"node test/success-tests/rebaseline.js","lint":"jshint lib && jshint test"},"dependencies":{"phantomjs":"^1.9.19","pn":"^1.0.0","yargs":"^3.31.0"},"devDependencies":{"chai":"^3.4.1","chai-as-promised":"^5.2.0","jshint":"^2.8.0","mkdirp":"^0.5.1","mocha":"^2.3.4","rimraf":"^2.5.0"},"gitHead":"ea9b9ed7a685f2e554fac50af8826b9c78a75467","bugs":{"url":"https://github.com/domenic/svg2png/issues"},"homepage":"https://github.com/domenic/svg2png#readme","_id":"svg2png@3.0.0","_shasum":"8ccc14c9d5483542aa43e24501fb65539b3877c4","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.3.0","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"8ccc14c9d5483542aa43e24501fb65539b3877c4","tarball":"http://registry-npm.ywwl.com/svg2png/download/svg2png-3.0.0.tgz","integrity":"sha512-PKttk4htDkQ+yMApxUeUJWi4kDJ0UfWx9xqFqPpWhy+FlHdmMcg+FZTbho7PFfaHuWFzBCFqb1bKOacWPg/OYg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpsYXuhagziC8KHEEe50BjNhXcliy20irG9xaoRkr/EgIhAITOr1XIloq7LQqgZHEiKGcfd1Imuni4QoHYONFcKYYI"}],"size":4626,"noattachment":false,"key":"/svg2png/-/svg2png-3.0.0.tgz"},"maintainers":[{"name":"domenic","email":"domenic@domenicdenicola.com"}],"directories":{},"readme":"# SVG-to-PNG Converter Using PhantomJS\n\nYou have a SVG file. For whatever reason, you need a PNG. **svg2png** can help.\n\n```js\nconst fs = require(\"pn/fs\"); // https://www.npmjs.com/package/pn\nconst svg2png = require(\"svg2png\");\n\nfs.readFile(\"source.svg\")\n    .then(svg2png)\n    .then(buffer => fs.writeFile(\"dest.png\", buffer))\n    .catch(e => console.error(e));\n```\n\nIn the above example, we use the `width` and `height` attributes specified in the SVG file to automatically determine the size of the SVG. You can also explicitly set the size:\n\n```js\nsvg2png(sourceBuffer, { width: 300, height: 400 })\n    .then(buffer => ...)\n    .catch(e => console.error(e));\n```\n\nThis is especially useful for images without `width` or `height`s. You can even specify just one of them and (if the image has an appropriate `viewBox`) the other will be set to scale.\n\nFinally, some SVG files reference external resources using relative paths. You can set them up for correct conversion by passing the `filename` or `url` option:\n\n```js\nsvg2png(sourceBuffer, { url: \"https://example.com/awesomeness.svg\" })\n    .then(buffer => ...)\n    .catch(e => console.error(e));\n\nsvg2png(sourceBuffer, { filename: path.resolve(__dirname, \"images/fun.svg\") })\n    .then(buffer => ...)\n    .catch(e => console.error(e));\n```\n\n## Sync variant\n\nThere's also a sync variant, for use in your shell scripts:\n\n```js\nconst outputBuffer = svg2png.sync(sourceBuffer, options);\n```\n\n## How the conversion is done\n\nsvg2png is built on the latest in [PhantomJS](http://phantomjs.org/) technology to render your SVGs using a headless WebKit instance. I have found this to produce much more accurate renderings than other solutions like GraphicsMagick or Inkscape. Plus, it's easy to install cross-platform due to the excellent [phantomjs](https://www.npmjs.com/package/phantomjs-prebuilt) npm package—you don't even need to have PhantomJS in your `PATH`.\n\nRendering isn't perfect; we have a number of issues that are [blocked on PhantomJS](https://github.com/domenic/svg2png/labels/blocked%20on%20phantomjs) getting its act together and releasing a cross-platform version with updated WebKit.\n\n## Exact resizing behavior\n\nPrevious versions of svg2png attempted to infer a good size based on the `width`, `height`, and `viewBox` attributes. As of our 3.0 release, we attempt to stick as close to the behavior of loading a SVG file in your browser as possible. The rules are:\n\n- Any `width` or `height` attributes that are in percentages are ignored and do not count for the subsequent rules.\n- The dimensions option `{ width, height }` overrides any `width` or `height` attributes in the SVG file, including for the subsequent rules. If a key is missing from the dimensions object (i.e. `{ width }` or `{ height }`) the corresponding attribute in the SVG file will be deleted.\n- `width` and `height` attributes without a `viewBox` attribute cause the output to be of those dimensions; this might crop the image or expand it with empty space to the bottom and to the right.\n- `width` and/or `height` attributes with a `viewBox` attribute cause the image to scale to those dimensions. If the ratio does not match the `viewBox`'s aspect ratio, the image will be expanded and centered with empty space in the extra dimensions. When a `viewBox` is present, one of either `width` or `height` can be omitted, with the missing one inferred from the `viewBox`'s aspect ratio.\n- When there are neither `width` nor `height` attributes, the promise rejects.\n\nOne thing to note is that svg2png does not and cannot stretch your images to new aspect ratios.\n\n## CLI\n\nThis package comes with a CLI version as well; you can install it globally with `npm install svg2png -g`. Use it as follows:\n\n```\n$ svg2png --help\nConverts SVGs to PNGs, using PhantomJS\n\nsvg2png input.svg [--output=output.png] [--width=300] [--height=150]\n\nOptions:\n  -o, --output  The output filename; if not provided, will be inferred  [string]\n  -w, --width   The output file width, in pixels                        [string]\n  -h, --height  The output file height, in pixels                       [string]\n  --help        Show help                                              [boolean]\n  --version     Show version number                                    [boolean]\n```\n\n## Node.js requirements\n\nsvg2png uses the latest in ES2015 features, and as such requires a recent version of Node.js. Only the 6.x series onward is supported.\n","publish_time":1452394568610,"_cnpm_publish_time":1452394568610,"dist-tags":{"latest":"4.1.1"}}