-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (45 loc) · 1.24 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
package main
import (
"fmt"
"net/http"
gd "github.com/bolknote/go-gd"
"github.com/gofrs/uuid"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.GET("/", createImage)
// Start server
e.Logger.Fatal(e.Start(":8080"))
}
func test(c echo.Context) error {
return c.String(http.StatusOK, "hello")
}
func createImage(c echo.Context) error {
pict := gd.CreateFromJpeg("images/bg.jpg")
head := gd.CreateFromJpeg("images/head.jpg")
destroy := func() {
fmt.Print("释放")
pict.Destroy()
head.Destroy()
}
defer destroy()
// white := pict.ColorAllocate(255, 255, 255)
head.CopyMerge(pict, 10, 10, 0, 0, 132, 132, 100)
// zhFont := "font/AdobeHeitiStd-Regular.otf"
// enBoldFont := "font/Helvetica Bold.ttf"
// enFont := "font/Helvetica.ttf"
// pict.StringFT(white, zhFont, 30, 0, 200, 200, "我试试中文的字体!")
// pict.StringFT(white, enFont, 20, 0, 100, 50, "12:02:02")
// pict.StringFT(white, enBoldFont, 30, 0, 100, 100, "2020-12-12")
uid := uuid.Must(uuid.NewV4()).String()
path := "outs/" + uid + ".jpg"
pict.Jpeg(path, 100)
return c.String(http.StatusOK, path)
}