-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.go
59 lines (47 loc) · 1.01 KB
/
generate.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
package main
import (
"encoding/csv"
"log"
"os"
"github.com/fogleman/gg"
)
func main() {
// Open the elements file.
f, err := os.Open("poster_elements.csv")
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Create a new CSV reader reading from the opened file.
reader := csv.NewReader(f)
// Read in all of the CSV records.
elementData, err := reader.ReadAll()
if err != nil {
log.Fatal(err)
}
for _, record := range elementData {
if err := generate(record[0], "output/"+record[0]+".png"); err != nil {
log.Fatal(err)
}
}
}
func generate(iso string, outFile string) error {
im, err := gg.LoadPNG("assets/how_to_wash.png")
if err != nil {
return err
}
w := im.Bounds().Size().X
h := im.Bounds().Size().Y
dc := gg.NewContext(w, h)
dc.DrawImage(im, 0, 0)
im, err = gg.LoadPNG("poster_text_render/" + iso + ".png")
if err != nil {
return err
}
iw := im.Bounds().Size().X
//h := im.Bounds().Size().Y
dc.DrawImage(im, w/2-iw/2, 230)
// Output
dc.SavePNG(outFile)
return nil
}