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