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

Why not add interface about return the IM #177

Open
angelsmall opened this issue Sep 23, 2022 · 0 comments
Open

Why not add interface about return the IM #177

angelsmall opened this issue Sep 23, 2022 · 0 comments

Comments

@angelsmall
Copy link

hi, fogleman. Thank you very much for your open source project, but I found a problem.
I need a drawn 'image.Image' object and use GO's native method 'Jpeg. Encode' to convert the 'image.Image' object into an IO.Writer object,then I find that the 'context. DrawImage' method does not modify the 'image.Image' object passed in. I think you may be to ensure the security of the 'image.Image' object. However, I found that there was no function in the project to get the ‘context.im’ object, which caused me some trouble when I just wanted to get the image data for network transfer, not SaveJPG() on my disk. Perhaps adding a method to return the ‘context.im’ is more convenient and flexible to use.

// i use code
// This is a little demo that rotates a circular image
// the test.jpg not rotate
func defaultDrawCore(im image.Image) {
w := im.Bounds().Size().X
h := im.Bounds().Size().Y
dc := gg.NewContext(w, h)
dc.DrawRectangle(0, 0, float64(w), float64(h))
dc.SetRGBA(255, 255, 255, 0)
dc.Fill()
radius := math.Min(float64(w), float64(h)) / 2
dc.DrawCircle(float64(w/2), float64(h/2), radius)
dc.Clip()
dc.RotateAbout(gg.Radians(45), float64(w/2), float64(h/2))
dc.DrawImage(im, 0, 0)
buf := new(bytes.Buffer)
jpeg.Encode(buf, im, &jpeg.Options{Quality: 90})
newim, imErr := jpeg.Decode(buf)
if imErr != nil {
return
}
gg.SaveJPG("test.jpg", newim, 90)
return
}

// Perhaps adding a function will solve this problem
func (dc *Context) GetIM() *image.RGBA {
return dc.im
}

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