Code Monkey home page Code Monkey logo

svghost's Introduction

SVG rendering with PhantomJS. https://npmjs.org/package/svghost


Need prerendered SVG, like graphs in emails? SVGhost is for you! Easily integrated into your pipeline, it's compatible with major projects and services such as D3 and AWS. For example:

var svg = d3.select('body')
  .append('svg')
  .attr('width', 100)
  .attr('height', 100);

...

svghost(svg.node().outerHTML, {
    width: svg.attr('width')
  , height: svg.attr('height')
}, function (err, img) {
  if (err) ...
  
  new AWS.S3().putObject({
      ...
    , Body: img
  }, ...);
});

svghost(svg, options, next)

  1. svg: String, XML document with an <svg> root.
  2. options: Object.
  • width: Number, required.
  • height: Number, required.
  • format: String, optional. png (default), gif, or jpeg.
  1. next(err, buffer): Function, called with the error (if any) and the rendered image Buffer (if successful).

svghost.getPhantom(next)
Returns the PhantomJS process (err, proc), starting it if necessary. Mostly useful for preloading PhantomJS, but you can also use the process normally.

svghost.setPhantom(proc)
Sets the PhantomJS process. Only useful if you have custom settings or a custom version or an otherwise previously existing process you'd like to use for rendering.

svghost.delPhantom()
Stops the PhantomJS process. Useful for cleaning up if you won't be using svghost for a while.


© 2014 SpotOn, shared under the MIT License.

svghost's People

Contributors

tkazec avatar

Stargazers

Ahmed Hashem avatar  avatar

Watchers

Kevin Farst avatar Cody Coljee-Gray avatar Ari Lazier avatar Patrick Salami avatar  avatar Toby Berster avatar Michael Yap avatar James Cloos avatar Smita Saxena avatar Charles Feng avatar Willem Franco avatar Yoni Zilberman avatar Paul Cowgill avatar Team SpotOn avatar Dimeji Abidoye avatar Nobel Yoo avatar Mark Cassetta avatar Aakash Japi avatar Cody Klein avatar Scott Jason avatar Chris DeLauder avatar Yash Saxena avatar Yacov Salomon avatar  avatar  avatar Jeffrey Ying avatar Juan Carlos Feris Gómez avatar Ilan avatar  avatar  avatar Lucas De Bortoli avatar Mike Yin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.