samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

createImageBitmap support #123

Open RReverser opened 1 year ago

RReverser commented 1 year ago

It would be great to support the standard createImageBitmap which async utility a lot like custom loadImage provided by this library, but with more control over rasterization.

jimmywarting commented 1 year ago

👍 Fully agree, i think the api should be more aligned with OffscrenCanvas and how it works in web workers.

import fs from 'node:fs'

const blob = await fs.openAsBlob(path)
const canvas = new OffscreenCanvas(width, height)
const bitmap = await createImageBitmap(blob)
const result = await canvas.convertToBlob(options)
jimmywarting commented 1 year ago

I also think that the Image class should eventually be removed and deprecated. And everybody should only use the createImageBitmap that way you could also remove simple-get which i do not think belongs in here.