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

Can't scale an image #186

Open Hirrolot opened 1 year ago

Hirrolot commented 1 year ago

I can't figure out how to scale an image. No matter which x, y parameters I feed to Scale, this method seems to be a no-op.

package main

import "github.com/fogleman/gg"

func main() {
    dc := gg.NewContext(1000, 1000)
    dc.DrawCircle(500, 500, 400)
    dc.SetRGB(0, 0, 0)
    dc.Fill()
    dc.Scale(10, 10)
    dc.SavePNG("out.png")
}

Maybe I've forgotten to call some other method that performs actual scaling?

mazznoer commented 1 year ago

@Hirrolot Try this.

package main

import (
    "github.com/fogleman/gg"
    "github.com/nfnt/resize"
)

func main() {
    dc := gg.NewContext(1000, 1000)
    dc.DrawCircle(500, 500, 400)
    dc.SetRGB(0, 0, 0)
    dc.Fill()
    //dc.Scale(10, 10)

    img := resize.Resize(10, 10, dc.Image(), resize.Lanczos2)

    dc = gg.NewContextForImage(img)
    dc.SavePNG("out.png")
}