Brooooooklyn / canvas

High performance skia binding to Node.js. Zero system dependencies and pure npm packages without any postinstall scripts nor node-gyp.
https://vercel.skia.rs
MIT License
1.78k stars 76 forks source link

The `source` parameter of the `loadImage` method cannot directly use Uint8Array. #919

Closed rambo-panda closed 3 weeks ago

rambo-panda commented 4 weeks ago

as stated in the question.

import { clearAllCache, createCanvas, loadImage } from '@napi-rs/canvas';

const imgBuf = await fetch(
  "https://cdn-ms.17zuoye.cn/zx-ptqlm/testing_2023_10_27/pdf_6d1e8d355613ef824d_0.webp",
).then((a) => a.arrayBuffer());

const imgBuf2 = await fetch(
  "https://cdn-ms.17zuoye.cn/zx-ptqlm/testing_2023_10_27/pdf_6d1e8d355613ef824d_0.webp",
).then((a) => a.arrayBuffer()).then(Buffer.from);

const imgByUint8Arr = await loadImage(imgBuf);
console.log("imgByUint8Arr", imgByUint8Arr.width, imgByUint8Arr.height);

const imgByBuffer = await loadImage(imgBuf2);
console.log("imgByBuffer", imgByBuffer.width, imgByBuffer.height);

image

https://github.com/Brooooooklyn/canvas/issues/890

rambo-panda commented 4 weeks ago

https://github.com/Brooooooklyn/canvas/pull/914/files