fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.34k stars 352 forks source link

Go concurrency #165

Open AriaFantom opened 2 years ago

AriaFantom commented 2 years ago

Is there any way to use go concurrency if it is there can anyone please provide and example, or else the image processing take 300ms+ to load i wanna make it fast with concurrency

dolmen commented 2 years ago

Please provide example code that would allow maintainers to reproduce your issue.

AriaFantom commented 2 years ago

Please provide example code that would allow maintainers to reproduce your issue.

I wanted an example of how can i use go concurrency if you want my code then

func admit(c *gin.Context) {

        var admit Admit
        c.BindJSON(&admit)
        im, err := gg.LoadImage("card.jpg")
        if err != nil {
            log.Fatal(err)
        }
        width := im.Bounds().Max.X
        height := im.Bounds().Max.Y
        dc := gg.NewContext(width, height)
        dc.SetRGB(0, 0, 0)
        dc.DrawImage(im, 0, 0)
        dc.SetRGB(1, 1, 1)
        dc.LoadFontFace("Roboto-Regular.ttf", 16)
        dc.SetHexColor("#542A18")
        dc.DrawString(admit.Username, 105, 493)
        dc.DrawString(admit.Date, 190, 634)
        var buf bytes.Buffer
        dc.EncodePNG(&buf)
        img := base64.StdEncoding.EncodeToString(buf.Bytes())
        c.JSON(200, gin.H{
            "image": img,
        })

}