-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"image/color"
"github.com/disintegration/imaging"
"github.com/fogleman/gg"
"github.com/pkg/errors"
)
func main() {
flag.Parse()
args := flag.Args()
dc := gg.NewContext(1200, 628)
backgroundImage, err := gg.LoadImage(args[0])
if err != nil {
panic(errors.Wrap(err, "load background image"))
}
backgroundImage = imaging.Fill(backgroundImage, dc.Width(), dc.Height(), imaging.Center, imaging.Lanczos)
dc.DrawImage(backgroundImage, 0, 0)
margin := 12.0
x := margin
y := margin
w := float64(dc.Width()) - (2.0 * margin)
h := float64(dc.Height()) - (2.0 * margin)
dc.SetColor(color.RGBA{0, 0, 0, 127})
dc.DrawRectangle(x, y, w, h)
dc.Fill()
fontPath := "./data/font/MPLUS1p-ExtraBold.ttf"
if err := dc.LoadFontFace(fontPath, 90); err != nil {
panic(errors.Wrap(err, "load font"))
}
dc.SetColor(color.White)
s := args[1]
maxWidth := float64(dc.Width())
dc.DrawStringWrapped(s, 50, 200, 0, 0, maxWidth/2, 1.5, gg.AlignLeft)
if err := dc.SavePNG(args[2]); err != nil {
panic(errors.Wrap(err, "save png"))
}
}