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

Fill a path with an Image #232

Open
Drylozu opened this issue Jul 1, 2023 · 3 comments
Open

Fill a path with an Image #232

Drylozu opened this issue Jul 1, 2023 · 3 comments

Comments

@Drylozu
Copy link

Drylozu commented Jul 1, 2023

Hi, thanks for creating such an awesome package like this! I want to draw a square image as a circle on a canvas. In JavaScript it would normally look like this:

ctx.beginPath();
ctx.arc(x, y, r, 0, 2*PI);
ctx.closePath();
ctx.clip();
// no matter where you draw, you will only see the "selected" part with the path
// - using ctx.save() before and ctx.restore() after can revert this
ctx.drawImage(0, 0, image);

I have tried several things but I still don't get the same effect.

@tdewolff
Copy link
Owner

tdewolff commented Jul 2, 2023

Yes you can, although it's not perfect yet for complex paths (especially self-intersecting paths fail). You can use the path logical operations for this:

p := &canvas.Path{}
// create path
p.Close()

clip := canvas.Circle(5.0)
p = p.And(clip)

ctx.SetFill(canvas.Red)
ctx.DrawPath(x, y, p)

Work is not complete on an image fill pattern yet.

@Drylozu
Copy link
Author

Drylozu commented Jul 3, 2023

In other words, it is not possible to make a square image into a round image?

@tdewolff
Copy link
Owner

tdewolff commented Jul 5, 2023

No, not yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants