Skip to content

Image#src= does not work with object URL (onload never called, cannot be drawn on 2d context) #2525

@UlyssesZh

Description

@UlyssesZh
import { Image } from 'canvas';
import { readFileSync } from 'fs';

const file = readFileSync('test.png');
const objectUrl = URL.createObjectURL(new Blob([file], { type: 'image/png' }));
const image = new Image();
image.onload = () => {
	URL.revokeObjectURL(objectUrl);
	console.log('in onload: complete =', image.complete); // never called
};
image.src = objectUrl;
console.log('immediately after setting src: complete =', image.complete); // true

If you try to draw an image with src being an object URL on a 2d context, you get Error: Image given has not completed loading.

Environment:

  • Node.js 22.14.0
  • canvas 3.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions