Skip to main content

Server-side Image generation for Polotno

Is it possible to generate images from polotno JSON on the backend?#

Yes. The is polotno-node package for such a use case.

Using polotno-node you can use most of Polotno Store API. The common usage is image generation from JSON generated by polotno:

const fs = require('fs');
// import polotno-node API
const { createInstance } = require('polotno-node');
async function run() {
// create working instance
const instance = await createInstance({
// to create your own API key please go here:
key: 'nFA5H9elEytDyPyvKL7T',
// load sample json
const json = JSON.parse(fs.readFileSync('polotno.json'));
// here you can manipulate JSON somehow manually
// for example replace some images or change text
// then we can convert json into image
const url = await instance.jsonToDataURL(json);
// prepare base64 string to save as localfile
var base64Data = url.replace(/^data:image\/png;base64,/, '');
// save it to local file
require('fs').writeFileSync('out.png', base64Data, 'base64');
// close instance