Automattic/node-canvas

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

已关闭

#2,525 创建于 2025年7月16日

 (2 条评论) (1 个反应) (0 位负责人)JavaScript (1,195 个派生)batch import
Good first issue

仓库指标

星标
 (10,689 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南