Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svg support? #6

Open
scientific-dev opened this issue Apr 5, 2021 · 5 comments
Open

Svg support? #6

scientific-dev opened this issue Apr 5, 2021 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@scientific-dev
Copy link

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()))
@DjDeveloperr
Copy link
Owner

SVG isn't supported at the moment. I'll look into that.

@scientific-dev
Copy link
Author

Thanks :)

@DjDeveloperr DjDeveloperr added the enhancement New feature or request label Jun 24, 2021
@DjDeveloperr DjDeveloperr added the help wanted Extra attention is needed label Jul 11, 2021
@konsumer konsumer mentioned this issue Sep 12, 2021
@konsumer
Copy link
Contributor

It looks like it's available in CanvasKit.Path.MakeFromSVGString, at least in new builds of canvaskit. I will work on a PR.

@konsumer
Copy link
Contributor

konsumer commented Sep 13, 2021

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.

@DjDeveloperr
Copy link
Owner

DjDeveloperr commented Sep 13, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants