DjDeveloperr / skia_canvas

Fast HTML Canvas API implementation for Deno using Google Skia
https://deno.land/x/skia_canvas
Apache License 2.0
124 stars 7 forks source link

SVG to ImageFormat #47

Open timonson opened 1 year ago

timonson commented 1 year ago

Is it possible with this library to convert SVGs to PNGs?

Thank you!

DjDeveloperr commented 1 year ago

Not possible right now, but something that is definitely wanted.

jdgamble555 commented 8 months ago

Got it working with rsvg_wasm:

import { createCanvas, loadImage } from "https://deno.land/x/canvas/mod.ts";
import { render } from "https://deno.land/x/resvg_wasm/mod.ts";

const svgImage = `...`;

const canvas = createCanvas(1600, 900);
const ctx = canvas.getContext('2d');

// render function from svg string here
const data = await render(svgImage);
const img = await loadImage(data);
ctx.drawImage(img, 0, 0);
const buffer = canvas.toBuffer('image/png');

J