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

crop.Circle returns empty image when passing it an image returned from img.SubImage #6

Open
meblum opened this issue Nov 3, 2023 · 0 comments

Comments

@meblum
Copy link

meblum commented Nov 3, 2023

Calling crop.Circle(cropImage(myImage, myRect), -1, 0) returns a blank image.

Here is the cropImage implementation:

// cropImage takes an image and crops it to the specified rectangle.
func cropImage(img image.Image, crop image.Rectangle) image.Image {
	type subImager interface {
		SubImage(r image.Rectangle) image.Image
	}

	// img is an Image interface. This checks if the underlying value has a
	// method called SubImage. If it does, then we can use SubImage to crop the
	// image. The image types in the std lib do implement it.
	simg, ok := img.(subImager)
	if !ok {
		panic("image does not support cropping")
	}

	return simg.SubImage(crop)
}
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

1 participant