deno-canvas
deno-canvas copied to clipboard
Svg support?
I am using deno-canvas for making a test image and i was using a svg image url to load image but whenever i try to load image it throws me a error Invalid Image. But when using nodejs's canvas it works fine. Is the problem with svg or something? Here is my code to reproduce the error:
import Canvas, { dataURLtoFile, loadImage } from 'https://deno.land/x/[email protected]/mod.ts';
ctx.fillStyle = '#7298da';
ctx.fillRect(0, 0, 800 - 20, 800 - 20);
ctx.fillStyle = 'white';
await ctx.drawImage(await loadImage('https://weboverhauls.github.io/demos/svg/checkmark.svg'), 0, 0);
Deno.writeFileSync("test.png", dataURLtoFile(canvas.toDataURL()))
SVG isn't supported at the moment. I'll look into that.
Thanks :)
It looks like it's available in CanvasKit.Path.MakeFromSVGString, at least in new builds of canvaskit. I will work on a PR.
Hmm, nevermind, seems like that just creates image-path.
I tried this:
console.log(canvas.Path.MakeFromSVGString(s))
where s is a SVG string, and got null. This seems doable, but I don't think it's directly related, so I'm not sure how.
It seems to transform SVG <path> to canvas Path, not actually parse SVG:
const path = Skia.Path.MakeFromSVGString(
`M0 18C0 8.059 8.059 0 18 0s18 8.059 18 18-8.059 18-18 18S0 27.941 0 18`,
);
but I think it should help in adding SVG support, I'll give this a try