broccoli-rsvg

SVG to PNG renderer for Broccoli

broccoli-rsvg

This Broccoli plugin renders SVG files to PNG using node-rsvg.

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:

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig # on OS X
npm install --save-dev broccoli-rsvg
var renderSvg = require('broccoli-rsvg');
 
var outputTree = renderSvg(inputTree, fileOptions);
  • inputTree: A tree that contains the SVG files you want to render.
  • fileOptions: A hash of rsvg options and alternative versions for each file; see the following example.
var renderSvg = require('broccoli-rsvg');
 
var png = renderSvg("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 
        transformerfunction(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: do not pass broccoli-svgo output to rsvg, it might get screwed up.

Copyright © 2014 myfreeweb This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.