toolpic-render

0.0.9 • Public • Published

Toolpic Render

This is a rendering API for Live Templates of toolpic project.

Install

$ npm install toolpic-render

Usage

Rendering ahppens within instances that share some general settings. To create them:

// Import fs
import fs from 'fs'
// Import module
import ToolpicRender from 'toolpic-render'

// Create instance
const app = new ToolpicRender({
  initFunctionName: 'render', // Optional, default value is 'render'
  // Specify wether we do not want to use the default headers by default (JPEG, PNG, SVG & PDF) (which generally does not make sense in the most cases)
  noDefaultHandlers: false // Optional, default value is false
});

// 1st: URL of live instance
// 2nd: Data object
// 3rd: Options
const rs = app.render('http://localhost:8888/live/strike/', {
  radius: 42
}, {
  width: 400, // Required, width of result
  height: 400, // Required, height of result
  // Delay to wait for images to be load
  delay: 101, // Optional, default = 100
  // Can be used to specify compression of JPEG images
  quality: 50, // Optional, default = 95
  //mime: 'application/pdf',
  // mime type of result
  mime: 'image/png', // Required!
});


// Create example write stream
const myWriteStream = fs.createWriteStream('test.png');
// Pipe the read stream to any write stream
rs.pipe(myWriteStream);

// Listen for finish event in write stream
myWriteStream.on('finish', () => {
  console.log("Successfully rendered image!");
  // Kill instance if we do not use it for additional rendering any more
  app.kill();
});

Readme

Keywords

Package Sidebar

Install

npm i toolpic-render

Weekly Downloads

21

Version

0.0.9

License

ISC

Unpacked Size

163 kB

Total Files

12

Last publish

Collaborators

  • mauriceconrad