-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (67 loc) · 1.76 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
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
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package main
import (
"encoding/csv"
"encoding/json"
"fmt"
"os"
"path"
"github.com/golang/freetype/truetype"
"github.com/simplycode07/certificate-cli/cmd"
"github.com/simplycode07/certificate-cli/generator"
)
func main() {
templatePath, blankCertificatePath, nameListPath := cmd.Execute()
var baseDir string = path.Dir(templatePath)
baseDir += "/"
fmt.Println("Base Directory:", baseDir)
fmt.Println("Template Path:", templatePath)
fmt.Println("Blank Certificate:", blankCertificatePath)
fmt.Println("Names of attendees:", nameListPath)
// read settings from template file
var template generator.Template
dataByte, _ := os.ReadFile(templatePath)
err := json.Unmarshal(dataByte, &template)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// read list of names from the csv file
nameBytes, err := os.Open(nameListPath)
names, err := csv.NewReader(nameBytes).ReadAll()
// _, err = csv.NewReader(nameBytes).ReadAll()
defer nameBytes.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
certificateByte, err := os.Open(blankCertificatePath)
defer certificateByte.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// read and parse font file
fontBytes, err := os.ReadFile(baseDir + template.Serial.Font)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
parsedFont, err := truetype.Parse(fontBytes)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
generator.Initialize(template, certificateByte, parsedFont, baseDir)
fmt.Println("NAMES: ")
for index, val := range names {
for _, name := range val{
generator.GenerateImage(template, name, index)
// fmt.Println("for name:", name)
// fmt.Println("serial generated: ", generator.GetSerial(template, index))
}
}
fmt.Println()
}