https://github.com/valpackett/broccoli-rsvg
A Broccoli plugin for rendering SVG files to PNG.
https://github.com/valpackett/broccoli-rsvg
broccoli broccoli-plugin rsvg svg
Last synced: 16 days ago
JSON representation
A Broccoli plugin for rendering SVG files to PNG.
- Host: GitHub
- URL: https://github.com/valpackett/broccoli-rsvg
- Owner: valpackett
- License: unlicense
- Created: 2014-03-30T17:35:33.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-04-11T17:10:21.000Z (about 10 years ago)
- Last Synced: 2025-03-20T09:05:39.012Z (about 1 year ago)
- Topics: broccoli, broccoli-plugin, rsvg, svg
- Language: JavaScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# broccoli-rsvg [](https://www.npmjs.org/package/broccoli-rsvg) [](https://www.npmjs.org/package/broccoli-rsvg) [](https://travis-ci.org/myfreeweb/broccoli-rsvg) [](https://gemnasium.com/myfreeweb/broccoli-rsvg) [](http://unlicense.org)
This [Broccoli] plugin renders SVG files to PNG using [node-rsvg].
[Broccoli]: https://github.com/joliss/broccoli
[node-rsvg]: https://github.com/2gis/node-rsvg
## Installation
First, get librsvg:
- OS X: `brew install librsvg`
- FreeBSD: `pkg install graphics/librsvg2`
- Ubuntu/Debian: `sudo apt-get install librsvg2-dev`
- Fedora/CentOS/OpenSUSE: `sudo yum install librsvg2-devel`
Second, install as any other broccoli plugin:
```bash
npm install --save-dev broccoli-rsvg
```
## Usage
```js
var renderSvg = require('broccoli-rsvg')
var outputTree = renderSvg(inputNodes, fileOptions)
```
- **`inputNodes`**: A list of nodes (trees) that contain the SVG files you want to render.
- **`fileOptions`**: A hash of rsvg options and alternative versions for each file; see the following example.
## Example
```js
var Rsvg = require('broccoli-rsvg')
var png = new Rsvg(['svg'], {
'logo.svg': {
width: 600,
height: 500, // optional override, values from the svg file itself are used by default
versions: [
{ // Retina version example
path: 'logo@2x.png',
width: 1200,
height: 1000
},
{ // Transformed version example
transformer: function(svg) {
return svg.replace('#000000', '#ffffff') // You can use elementtree or xmldom here...
},
path: 'logo-black.png',
versions: [
{ // Nested example: transformed + retina
path: 'logo-black@2x.png',
width: 1200,
height: 1000
}
]
}
]
}
})
return [svg, png]
```
**Note**: avoid passing [broccoli-svgo] output to rsvg, it might get screwed up.
[broccoli-svgo]: https://github.com/sindresorhus/broccoli-svgo
## Contributing
Please feel free to submit pull requests!
By participating in this project you agree to follow the [Contributor Code of Conduct](http://contributor-covenant.org/version/1/4/).
## License
This is free and unencumbered software released into the public domain.
For more information, please refer to the `UNLICENSE` file or [unlicense.org](http://unlicense.org).