-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (62 loc) · 1.43 KB
/
main.go
File metadata and controls
79 lines (62 loc) · 1.43 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"log"
"os"
"strings"
"time"
"github.com/fogleman/gg"
)
func main() {
generateTicket(14)
}
func generateTicket(amount int64) {
var hours24 int64 = 86400
var multiplier int64 = 0
for multiplier = 0; multiplier < amount; multiplier++ {
// get todays date to start creating tickets from
today := time.Now()
now := time.Unix(today.Unix()+hours24*multiplier, 0)
// Letters for day
uc := strings.ToUpper(fmt.Sprintf("%s", now.Weekday()))
day := uc[:2]
// the day number
dayNum := fmt.Sprintf("%d", now.Day())
if len(dayNum) == 1 {
dayNum = "0" + dayNum
}
// month number
month := fmt.Sprintf("%d", now.Month())
if len(month) == 1 {
month = "0" + month
}
dateStr := day + " " + dayNum + "/" + month
// Make the ticket
importImg(dateStr)
}
}
func importImg(date string) {
im, err := gg.LoadImage("source.png")
if err != nil {
log.Fatal(err)
}
dc := gg.NewContext(1645, 708)
dc.SetRGBA(1, 1, 1, 0)
dc.Clear()
dc.SetRGB(0, 0, 0)
if err := dc.LoadFontFace("fonts/Ubuntu-C.ttf", 192); err != nil {
panic(err)
}
dc.DrawImage(im, 0, 0)
dc.DrawStringAnchored(date, 250, 400, 0, 0)
filename := strings.Replace(date, "/", " ", -1)
// make output dir
if _, err = os.Stat("output/"); os.IsNotExist(err) {
os.Mkdir("output/", 0700)
}
err = dc.SavePNG("output/" + filename + ".png")
if err != nil {
fmt.Println(err)
}
fmt.Printf("Generated %s.png\n", filename)
}