gg icon indicating copy to clipboard operation
gg copied to clipboard

Can't scale an image

Open hirrolot opened this issue 1 year ago • 1 comments

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?

hirrolot avatar Mar 31 '23 23:03 hirrolot

@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")
}

mazznoer avatar May 19 '23 23:05 mazznoer