Can't load svg with base64 image inside with node-canvas

1.1k views Asked by At


I have an issue when load svg ( with base64 image inside ) file using function loadImage I get exception:

GdkPixbuf-CRITICAL **: 13:03:49.842: gdk_pixbuf_get_width: assertion 'GDK_IS_PIXBUF (pixbuf)' failed

Here is my code & test svg file:

const fs = require('fs');
const { createCanvas, loadImage } = require('canvas');

async function nodeCanvasTest() {
  console.log('starting...');
  const canvas = createCanvas(400, 200);
  const ctx = canvas.getContext('2d');

  image = await loadImage('./input.svg');

  ctx.drawImage(image, 0, 0);
  var stream = canvas.createPNGStream();
  stream.pipe(fs.createWriteStream('output.png'));
  console.log('completed');
}

nodeCanvasTest();

svg file: https://github.com/Automattic/node-canvas/files/4774170/input.svg.zip

When I run command:
node server.js

I get error:

enter image description here


My environments:


Please help me resolve this problem.

Is there any document guide to build node-canvas from source so I can build and debug with node-canvas ( some guides are out of date and have many compile errors ).

Thank you!

0

There are 0 answers