Automattic/node-canvas

Can't load svg with base64 image inside

Aperta

#1607 aperta il 13 giu 2020

 (8 commenti) (6 reazioni) (0 assegnatari)JavaScript (1195 fork)batch import
BugGood first issueHelp wanted

Metriche repository

Star
 (10.688 stelle)
Metriche merge PR
 (Merge medio 34g 18h) (2 PR mergiate in 30 g)

Descrizione

Issue or Feature

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

Steps to Reproduce

  1. Run following code to load 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();

Here is svg file:

input.svg.zip

  1. In the terminal run command: node server.js

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

error_load_svg_with_base64

Your Environment

OS: MacOS Catalina 10.15.5 Node: v10.16.0 NPM: 6.9.2 Canvas: canvas@2.6.1

Expected:

SVG file is loaded & rendered normally.

Guida contributor