{"_id":"@digidem/svg-to-img","_rev":"6-12fefffb20bc8a38bc48b9f3b18fc9c9","name":"@digidem/svg-to-img","dist-tags":{"latest":"2.1.0"},"versions":{"2.1.0":{"name":"@digidem/svg-to-img","version":"2.1.0","keywords":["svg","png","jpg","jpeg","image","puppeteer","node"],"author":{"url":"http://etiennemartin.ca/","name":"Etienne Martin"},"license":"MIT","_id":"@digidem/svg-to-img@2.1.0","maintainers":[{"name":"andrew_chou","email":"andrewchou@fastmail.com"},{"name":"substack","email":"substack@gmail.com"},{"name":"karissa","email":"krmckelv@gmail.com"},{"name":"digidem-admin","email":"info@digital-democracy.org"},{"name":"gmaclennan","email":"gmaclennan@digital-democracy.org"},{"name":"noffle","email":"kira@eight45.net"}],"homepage":"https://github.com/digidem/svg-to-img","bugs":{"url":"https://github.com/digidem/svg-to-img/issues"},"dist":{"shasum":"b991d6b1a5ee1046b1ff74fd9260b0380b0e9102","tarball":"https://registry.npmjs.org/@digidem/svg-to-img/-/svg-to-img-2.1.0.tgz","fileCount":10,"integrity":"sha512-5g3ln2sjcsjl/lr90qGP1AIfKV+Y45AN7zGcVepIYMneDqOvPozUt667nSDI9ayIupdYUaGQm7OX44NIplXv3A==","signatures":[{"sig":"MEYCIQDTLC4vtTIzyaSPIMcNcXPG252VfAVzirlq/AqOFZxhjQIhANS3bjMsQA7KHhkBmPvY6GPEd5TOQlwlpHGXCKW2LNe2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":20561,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzwh1CRA9TVsSAnZWagAAvVkP/3HMmlm5+NDMfOsxWpnD\nEJMG+6k07BPAaqLMoeO7qeVVQn5bzhw+Ea1LIlJocaTRai0hCoQ/RZtFDTgM\nMbM7OsdLsKs7shBrvSozI7HftE6KAOKiKHqrMelm6M2dvzMeLOBIyrECx3Rh\nB4HybZ+W4VYxQWV/AXNQeaandxd66YTSDaoRpUHbCfI9eQFg8st0iDAr7/Uh\nHcCgQ3tAd1jrwGRegr8Wmquia+iyI9hdzs8eqcuA82j08TYY8WeB3b71Bv2p\ny+TlLqpPMaepLVuh6tBeqZAvkDnMPd+qG/w9TpsOgTEu0rTrnIWADZgMmywc\nh66tpHc3fOUqT0lloEWay94Mhh0BYAZ9k3UX81vsTAZV8yrqTW5fJWYxTh2D\nGundAFpNm5VSZLWU6vciTnKXTCprAwUHuRJGqNmI/N4xpWmzAAdcbkCM4a67\n4p7eBEJE+7nxbM+erZlDXgyXOlipfEIjt8sxDwJ9jVUi3vNHNPndTliDKSrk\nQosisnRVTC0jc4hz9lSCnxAUuB/w1+HQhuia2+lLJ0H52ffjMcAKya7emXLl\nbdcGK0f0PDxgUWgOMPoQIICUSRGR1bIinfsofRRMvuGYUXsguo4DIp4xHheh\n/6ZbaacwCPNUcusJ9N0eeVr6x/sSibcuTd8/UWCSkbUySY/2nluL1y49p3DO\nr7dZ\r\n=F6uq\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testURL":"http://localhost","testMatch":["**/?(*.)(test).(tsx|ts)"],"transform":{"^.+\\.tsx?$":"ts-jest"},"setupFiles":["jest-canvas-mock"],"coverageThreshold":{"global":{"lines":100,"branches":100,"functions":100,"statements":-10}},"collectCoverageFrom":["src/**/*.(tsx|ts)"],"moduleFileExtensions":["ts","tsx","js","jsx","json","node"],"coveragePathIgnorePatterns":["/node_modules/","/coverage/","/dist/","/typings/","/tests/"]},"main":"dist/index.js","husky":{"hooks":{"pre-push":"npm run build && npm run test","pre-commit":"npm run build && npm run test"}},"types":"dist/index.d.ts","engines":{"node":">= 7.6.0"},"gitHead":"78bbce41ef6ed652097791687a4a25114d50b721","scripts":{"dev":"tsc --pretty --watch","lint":"tslint -c tslint.json -p tsconfig.json --fix","test":"jest src --coverage --verbose","build":"tsc --pretty","prepare":"npm run build","pretest":"npm run lint","coverage":"coveralls < ./coverage/lcov.info","prebuild":"rm -rf dist/ && npm run lint","test:watch":"jest src --coverage --verbose --watch"},"_npmUser":{"name":"andrew_chou","email":"andrewchou@fastmail.com"},"repository":{"url":"git+https://github.com/digidem/svg-to-img.git","type":"git"},"_npmVersion":"6.14.15","description":"A node.js library to convert SVGs to images built with Puppeteer.","directories":{},"_nodeVersion":"14.18.0","dependencies":{"puppeteer":"1.1.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"22.4.4","husky":"0.15.0-rc.13","rimraf":"2.6.2","tslint":"5.11.0","ts-jest":"22.4.6","coveralls":"3.0.2","image-size":"0.6.3","typescript":"2.9.2","@types/jest":"22.2.3","@types/rimraf":"2.0.2","@types/puppeteer":"1.10.1","jest-canvas-mock":"1.1.0","@types/image-size":"0.0.29","tslint-eslint-rules":"4.1.1","tslint-config-prettier":"1.17.0"},"_npmOperationalInternal":{"tmp":"tmp/svg-to-img_2.1.0_1636649483590_0.8593770576581046","host":"s3://npm-registry-packages"}}},"time":{"created":"2021-11-11T16:51:23.515Z","modified":"2025-09-18T09:24:43.505Z","2.1.0":"2021-11-11T16:51:23.754Z"},"bugs":{"url":"https://github.com/digidem/svg-to-img/issues"},"author":{"url":"http://etiennemartin.ca/","name":"Etienne Martin"},"license":"MIT","homepage":"https://github.com/digidem/svg-to-img","keywords":["svg","png","jpg","jpeg","image","puppeteer","node"],"repository":{"url":"git+https://github.com/digidem/svg-to-img.git","type":"git"},"description":"A node.js library to convert SVGs to images built with Puppeteer.","maintainers":[{"email":"developer@awana.digital","name":"digidem-admin"},{"email":"gmaclennan@digital-democracy.org","name":"gmaclennan"},{"email":"andrewchou@fastmail.com","name":"andrew_chou"}],"readme":"# svg-to-img\n\n#### A node.js library to convert SVGs to images built with [Puppeteer](https://github.com/GoogleChrome/puppeteer).\n\n\n[![Coveralls github](https://img.shields.io/coveralls/github/etienne-martin/svg-to-img.svg)](https://coveralls.io/github/etienne-martin/svg-to-img)\n[![CircleCI build](https://img.shields.io/circleci/project/github/RedSparr0w/node-csgo-parser.svg)](https://circleci.com/gh/etienne-martin/svg-to-img)\n[![node version](https://img.shields.io/node/v/svg-to-img.svg)](https://www.npmjs.com/package/svg-to-img)\n[![npm version](https://img.shields.io/npm/v/svg-to-img.svg)](https://www.npmjs.com/package/svg-to-img)\n[![npm monthly downloads](https://img.shields.io/npm/dm/svg-to-img.svg)](https://www.npmjs.com/package/svg-to-img)\n\n## Getting Started\n\n### Installation\n\nTo use svg-to-img in your project, run:\n\n```bash\nnpm install svg-to-img -S\n```\n\nNote: When you install svg-to-img, it downloads a recent version of Chromium (~170Mb Mac, ~282Mb Linux, ~280Mb Win) that is guaranteed to work with the library.\n\n#### Debian\n\nIf you're planning on running svg-to-img on Debian, you will need to manually install the following dependencies:\n\n```bash\n#!/bin/bash\n\napt-get update\napt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \\\n  libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \\\n  libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \\\n  libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \\\n  ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget\n```\n\n### Usage\n\nCaution: svg-to-img uses async/await which is only supported in Node v7.6.0 or greater.\n\n**Example** - converting a `svg` to `png`:\n\n```javascript\nconst svgToImg = require(\"svg-to-img\");\n\n(async () => {\n  const image = await svgToImg.from(\"<svg xmlns='http://www.w3.org/2000/svg'/>\").toPng();\n  \n  console.log(image);\n})();\n```\n\n**Example** - converting a `svg` to `jpeg` and saving the image as *example.jpeg*:\n\n```javascript\nconst svgToImg = require(\"svg-to-img\");\n\n(async () => {\n  await svgToImg.from(\"<svg xmlns='http://www.w3.org/2000/svg'/>\").toJpeg({\n    path: \"./example.jpeg\"\n  });\n})();\n```\n\n**Example** - resizing a `svg` proportionally and converting it to `webp`:\n\n```javascript\nconst svgToImg = require(\"svg-to-img\");\n\n(async () => {\n  const image = await svgToImg.from(\"<svg xmlns='http://www.w3.org/2000/svg'/>\").toWebp({\n    width: 300\n  });\n  \n  console.log(image);\n})();\n```\n\n**Example** - converting a `svg` to base64-encoded png:\n\n```javascript\nconst svgToImg = require(\"svg-to-img\");\n\n(async () => {\n  const image = await svgToImg.from(\"<svg xmlns='http://www.w3.org/2000/svg'/>\").toPng({\n    encoding: \"base64\"\n  });\n  \n  console.log(image);\n})();\n```\n\n## API Documentation\n\n### svgToImg.from(svg)\n- `svg` <Buffer|string>  SVG markup to be converted.\n- returns: <[Svg]> a new Svg object.\n\nThe method returns a svg instance based on the given argument.\n\n### svg.to([options])\n- `options` <[Object]> Options object which might have the following properties:\n  - `path` <[string]> The file path to save the image to. The image type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the image won't be saved to the disk.\n  - `type` <[string]> Specify image type, can be either `png`, `jpeg` or `webp`. Defaults to `png`.\n  - `quality` <[number]> The quality of the image, between 0-1. Defaults to `1`. Not applicable to `png` images.\n  - `width` <[number]> width of the output image. Defaults to the natural width of the SVG.\n  - `height` <[number]> height of the output image. Defaults to the natural height of the SVG.\n  - `clip` <[Object]> An object which specifies clipping region of the output image. Should have the following fields:\n    - `x` <[number]> x-coordinate of top-left corner of clip area\n    - `y` <[number]> y-coordinate of top-left corner of clip area\n    - `width` <[number]> width of clipping area\n    - `height` <[number]> height of clipping area\n  - `background` <[string]> background color applied to the output image, must be a valid [CSS color value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).\n  - `encoding` <[string]> Specify encoding, can be either `base64`, `utf8`, `binary` or `hex`. Returns a `Buffer` if this option is omitted.\n  - `destroyBrowserTimeout` <[number]> Specify timeout (in milliseconds) used for scheduling browser destruction. Defaults to `500`. This is useful if you need to increase it due to usage with something like `Promise.all` (see [relevant issue](https://github.com/etienne-martin/svg-to-img/issues/22))\n- returns: <[Promise]<Buffer|String>> Promise which resolves to the output image.\n\n### svg.toPng([options])\n- `options` <[Object]> Optional options object that can have the same properties as the `to` method except for the type property.\n- returns: <[Promise]<Buffer|String>> Promise which resolves to the `png` image.\n\nThis method is simply a shorthand for the `to` method.\n\n### svg.toJpeg([options])\n- `options` <[Object]> Optional options object that can have the same properties as the `to` method except for the type property.\n- returns: <[Promise]<Buffer|String>> Promise which resolves to the `jpeg` image.\n\nThis method is simply a shorthand for the `to` method.\n\n### svg.toWebp([options])\n- `options` <[Object]> Optional options object that can have the same properties as the `to` method except for the type property.\n- returns: <[Promise]<Buffer|String>> Promise which resolves to the `webp` image.\n\nThis method is simply a shorthand for the `to` method.\n\n## Built with\n\n* [node.js](https://nodejs.org/en/) - Cross-platform JavaScript run-time environment for executing JavaScript code server-side. \n* [Puppeteer](https://github.com/GoogleChrome/puppeteer/) - Headless Chrome Node API.\n* [TypeScript](https://www.typescriptlang.org/) - Typed superset of JavaScript that compiles to plain JavaScript.\n* [Jest](https://facebook.github.io/jest/) - Delightful JavaScript Testing.\n\n## Contributing\n\nWhen contributing to this project, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.\n\nUpdate the [README.md](https://github.com/etienne-martin/svg-to-img/blob/master/README.md) with details of changes to the library.\n\nExecute `npm run test` and update the [tests](https://github.com/etienne-martin/svg-to-img/tree/master/src/tests) if needed.\n\n## Authors\n\n* **Etienne Martin** - *Initial work* - [etiennemartin.ca](http://etiennemartin.ca/)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/etienne-martin/svg-to-img/blob/master/LICENSE) file for details.\n","readmeFilename":"README.md"}