gg/examples/rotated-image.go

35 lines
807 B
Go
Raw Normal View History

2016-12-08 04:16:19 +01:00
package main
import "github.com/fogleman/gg"
func main() {
const W = 400
2017-01-08 09:18:14 +01:00
const H = 500
2016-12-08 04:16:19 +01:00
im, err := gg.LoadPNG("examples/gopher.png")
if err != nil {
panic(err)
}
2017-01-08 09:18:14 +01:00
iw, ih := im.Bounds().Dx(), im.Bounds().Dy()
2016-12-08 04:16:19 +01:00
dc := gg.NewContext(W, H)
// draw outline
dc.SetHexColor("#ff0000")
dc.SetLineWidth(1)
dc.DrawRectangle(0, 0, float64(W), float64(H))
dc.Stroke()
2017-01-08 09:18:14 +01:00
// draw full image
dc.SetHexColor("#0000ff")
dc.SetLineWidth(2)
dc.DrawRectangle(100, 210, float64(iw), float64(ih))
dc.Stroke()
dc.DrawImage(im, 100, 210)
2016-12-08 04:16:19 +01:00
// draw image with current matrix applied
dc.SetHexColor("#0000ff")
dc.SetLineWidth(2)
dc.Rotate(gg.Radians(10))
2017-01-08 09:18:14 +01:00
dc.DrawRectangle(100, 0, float64(iw), float64(ih)/2+20.0)
2016-12-08 04:16:19 +01:00
dc.StrokePreserve()
dc.Clip()
2017-01-08 09:18:14 +01:00
dc.DrawImageAnchored(im, 100, 0, 0.0, 0.0)
2016-12-08 04:16:19 +01:00
dc.SavePNG("out.png")
}