npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sevruga

v0.1.7

Published

Library to perform rendering from .svg files to Node.JS buffers.

Downloads

30

Readme

sevruga

A Node.JS binding for librsvg.

Installation

Prerequisites

Install the librsvg library and header files. Usually you have to look for a development package version. You must also have a functioning build tool chain including pkg-config. You can find instructions for different operating systems below:

  • Ubuntu:

    sudo apt-get install librsvg2-dev
  • Mac OS X:

    brew install librsvg

    If, after installing LibRSVG through homebrew you are experiencing not found issues when installing this module, try manually exporting the package config path for any not found package with a command like this:

    export PKG_CONFIG_PATH=/usr/local/opt/zlib/lib/pkgconfig

    Then try reinstalling this module.

  • Windows:

    Install msys2. Follow the instructions to ensure all packages are up-to-date. The installer defaults to install at C:\msys64. If you install to a different path you will need to update the GTK_Root variable in binding.gyp.

    Install build tools and librsvg via the pacman package manager:

    pacman -S mingw-w64-x86_64-toolchain base-devel
    pacman -S mingw-w64-x86_64-librsvg

Install Node.JS LTS for your platform, currently the latest v10.

Install the C++ build tools node-gyp by following the installation instructions.

Using sevruga as a dependency

Install sevruga into your project by running the npm install command in its root folder:

npm install sevruga

Note that the --save option is now the default.

Building sevruga

  1. Clone this project with git clone https://github.com/Streampunk/sevruga.git
  2. Enter the project folder with cd sevruga
  3. Run npm install

Using sevruga

sevruga exports the function renderSVG that returns a promise that will be resolved when the supplied SVG data has been parsed and rendered to the supplied buffer according to the supplied width and height parameters. Timing parameters for the stages of render are available from the returned object as shown in the example below.

renderSVG requires three parameters:

  1. A string containing the svg definition
  2. An allocated buffer of sufficient size for the render results.
  3. A params object which must include width and height members. An optional pngPath can be provided which if present will cause the output of a png version of the render result at the path provided.
const sevruga = require('sevruga');
const fs = require('fs');

async function svgTest() {
  const svgStr = fs.readFileSync(`${__dirname}/svg/Test.svg`, { encoding: 'utf8' }); // returns a string

  const params = { width: 1920, height: 1080 };
  const renderBuf = Buffer.alloc(params.width * params.height * 4); // ARGB 8-bit per component  

  const t = await sevruga.renderSVG(svgStr, renderBuf, params);
  console.log(`Parse: ${t.parseTime}, Render: ${t.renderTime}, Total: ${t.totalTime}`);
}
svgTest()
  .catch(err => console.log(`Sevruga render failed: ${err}`));

A Node.js transform stream implementation is also available. This allows a stream of SVG files to be processed, producing a stream of rendered buffers. This approach supports back-pressure so that there will be a limit on resources consumed.

const sevruga = require('../index.js');
const fs = require('fs');

function svgStreamTest() {
  const svgStr = fs.readFileSync(`${__dirname}/svg/Test.svg`, { encoding: 'utf8' });
  const params = { width: 1920, height: 1080 };
  svgStream = sevruga.createRenderStream(params)
  svgStream.on('data', buf => {
    const t = buf.timings;
    console.log(`Parse: ${t.parseTime}, Render: ${t.renderTime}, Total: ${t.totalTime}`);
  });
  svgStream.on('error', console.error);

  let i = 10;
  const write = str => {
    var ok = true;
    do {
      i -= 1;
      if (i === 0) {
        // last time!
        svgStream.end(str);
      } else {
        ok = svgStream.write(str, 'utf8');
        // console.log('Write data', ok);
      }
    } while (i > 0 && ok);
    if (i > 0) {
      // had to stop early!
      // write some more once it drains
      // console.log("So draining.");
      svgStream.once('drain', () => write(svgStr));
    }
  }
  write(svgStr);
}
svgStreamTest();

Status, support and further development

Contributions can be made via pull requests and will be considered by the author on their merits. Enhancement requests and bug reports should be raised as github issues. For support, please contact Streampunk Media.

License

This software is released under the Apache 2.0 license. Copyright 2018 Streampunk Media Ltd.