diff --git a/cmd/cmd b/cmd/cmd new file mode 100755 index 0000000000000000000000000000000000000000..9757ce101be7f0b918d20315fe1dea9a444bed33 Binary files /dev/null and b/cmd/cmd differ diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 0000000000000000000000000000000000000000..765a372c9b2518ef14c84cd61a72b8d116a352b2 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,12 @@ +package main + +import ( + "mock/router" +) + +func main() { + + r := router.InitRouter() + r.Run(":8080") + +} \ No newline at end of file diff --git a/controller/controller.go b/controller/controller.go new file mode 100644 index 0000000000000000000000000000000000000000..4fdeac99b83e34fe6c24b33f22313234fd9705bc --- /dev/null +++ b/controller/controller.go @@ -0,0 +1,73 @@ +package controller + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "mock/lib/font/config" + . "mock/util" + + uuid "github.com/satori/go.uuid" +) + +func Index(c *gin.Context) { + c.HTML(http.StatusOK, "index.tmpl", nil) + // c.JSON(http.StatusOK, gin.H{ + // "author": "yushanma", + // "page": "index", + // "usage": "请求示例 curl 127.0.0.1:8080/GetImg/:worlds/:horV/:font ", + // "param": "其中worlds为字符;horV为H水平/V为垂直;font为font1/font2两种字体", + // }) +} + +// 参数 worlds,horV,font => 春联内容,方向,字体 +func GetImg(c *gin.Context) { + + // ================== 参数处理 + worlds := c.PostForm("worlds") + // 处理字符 + var charset []string + if len(worlds) > 0 { + for _, v := range worlds { + charset = append(charset, string(v)) + } + } else { + charset = []string{"你", "好", "世", "界"} + } + + // 处理方向 + horV := c.PostForm("horV") + if len(horV) > 0 { + if horV != "H" && horV != "V" { + horV = "H" + } + } else { + horV = "H" + } + + // 输出路径 + outPath := "../res/" + uuid.NewV4().String() + ".png" + + // 处理字体 + font := config.Font_1 + ft := c.PostForm("font") + if len(ft) > 0 { + if ft != "font1" && ft != "font2" { + font = config.Font_1 + } + } else { + font = config.Font_1 + } + + // 生成对联 + Generator(charset, outPath, horV, font) + + // 返回数组 + urls := []string{outPath} + + c.JSON(http.StatusOK, gin.H{ + "status": "success", + "urls": urls, + }) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..c310ae47bcc935c743cfcb2460f88ffa2de69cd8 --- /dev/null +++ b/go.mod @@ -0,0 +1,32 @@ +module mock + +go 1.18 + +require ( + github.com/gin-contrib/cors v1.4.0 + github.com/gin-gonic/gin v1.8.1 + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 + github.com/satori/go.uuid v1.2.0 +) + +require ( + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.0 // indirect + github.com/goccy/go-json v0.9.7 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/ugorji/go/codec v1.2.7 // indirect + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect + golang.org/x/image v0.1.0 // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect + golang.org/x/text v0.4.0 // indirect + google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..669f32cb9403bad4ea8411b5aea3195ecd54c2c1 --- /dev/null +++ b/go.sum @@ -0,0 +1,104 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= +github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= +golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/img/bg.png b/img/bg.png new file mode 100644 index 0000000000000000000000000000000000000000..545bd837e91fdd704c18eae4728df4ff90647159 Binary files /dev/null and b/img/bg.png differ diff --git a/index.html b/index.html deleted file mode 100644 index c126492dddd2b17dc640b818f7c5aadbc79687ff..0000000000000000000000000000000000000000 --- a/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Document - - - -
- -

欢迎使用 Cloud IDE

- 官网:https://ide.csdn.net -
- - \ No newline at end of file diff --git a/lib/font/config/config.go b/lib/font/config/config.go new file mode 100644 index 0000000000000000000000000000000000000000..5ed3d39da55d94f0761c584f50fbd5f9864ca853 --- /dev/null +++ b/lib/font/config/config.go @@ -0,0 +1,11 @@ +package config + +type TextFont struct { + FontName string // 字体名称 + FontSize float64 // 字体大小 + X, Y int // 字体渲染位置 +} + +var Font_1 = TextFont{"方正楷体简体.ttf", 390, 60, 520} + +var Font_2 = TextFont{"演示夏行楷.ttf", 390, 0, 550} diff --git "a/lib/font/\346\226\271\346\255\243\346\245\267\344\275\223\347\256\200\344\275\223.ttf" "b/lib/font/\346\226\271\346\255\243\346\245\267\344\275\223\347\256\200\344\275\223.ttf" new file mode 100644 index 0000000000000000000000000000000000000000..1ef705335a476682cfcb2ab1e626941478057252 Binary files /dev/null and "b/lib/font/\346\226\271\346\255\243\346\245\267\344\275\223\347\256\200\344\275\223.ttf" differ diff --git "a/lib/font/\346\274\224\347\244\272\345\244\217\350\241\214\346\245\267.ttf" "b/lib/font/\346\274\224\347\244\272\345\244\217\350\241\214\346\245\267.ttf" new file mode 100644 index 0000000000000000000000000000000000000000..33e6bbcf273993ac69db8b819b2b614887a90593 Binary files /dev/null and "b/lib/font/\346\274\224\347\244\272\345\244\217\350\241\214\346\245\267.ttf" differ diff --git a/middleware/cors_middleware.go b/middleware/cors_middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..5ae4fa9cf70964021743b4c4519b81716674fdb4 --- /dev/null +++ b/middleware/cors_middleware.go @@ -0,0 +1,50 @@ +package middleware +import ( + "github.com/gin-contrib/cors" + "github.com/gin-gonic/gin" + "time" + ) + + // 跨域请求 + + func Cors() gin.HandlerFunc { + handlerFunc := cors.New(cors.Config{ + AllowMethods: []string{"*"}, + AllowHeaders: []string{"content-type", "token", "fileType", "size", "digest"}, //此处设置非默认之外的请求头(自定义请求头),否则会出现跨域问题 + AllowAllOrigins: true, + AllowCredentials: true, + MaxAge: 24 * time.Hour, + ExposeHeaders: []string{"*"}, + }) + return handlerFunc + } + + // gin 上下文配置 cors + + func CORSMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + c.Writer.Header().Set("Access-Control-Allow-Origin", "*") + c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") + c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With") + c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, HEAD, OPTIONS") + + if c.Request.Method == "OPTIONS" { + c.AbortWithStatus(204) + return + } + + c.Next() + } + } + + //nginx 跨域 + + //server { + //#以上省略 + //add_header 'Access-Control-Allow-Origin' '*'; + //add_header 'Access-Control-Allow-Headers' 'X-Pagination-Current-Page,Content-Type'; + //add_header 'Access-Control-Allow-Methods' 'PUT,GET,POST,HEAD,DELETE'; + //add_header 'Access-Control-Expose-Headers' 'X-Pagination-Current-Page,Content-Type'; + //#以下省略 + //} + //Allow-Headers "Accept","Accept-Encoding","Host","Origin","Referer","User-Agent", \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 99a39dd58849de44a4ca201086854b7be271bb8f..0000000000000000000000000000000000000000 --- a/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "cloud-ide-1024-game", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "dev": "live-server" - }, - "author": "Aresn", - "license": "MIT", - "dependencies": { - "live-server": "^1.2.2" - } -} diff --git a/preview.yml b/preview.yml index 48e3adc5acc31b5898cdbf7f6b07ff22a683b69c..f269f6b0a5934a12e7fd7c71469225d9030d5e0c 100644 --- a/preview.yml +++ b/preview.yml @@ -1,10 +1,8 @@ -# preview.yml -autoOpen: true # 打开工作空间时是否自动开启所有应用的预览 +autoOpen: true apps: - - port: 3000 # 应用的端口 - run: npm i && npm run dev # 应用的启动命令 - command: # 使用此命令启动服务,且不执行run - root: ./ # 应用的启动目录 - name: 1024云IDE挑战赛项目 # 应用名称 - description: 1024云IDE挑战赛项目。 # 应用描述 - autoOpen: true # 打开工作空间时是否自动开启预览(优先级高于根级 autoOpen \ No newline at end of file + - port: 8080 + command: go env -w GOPROXY=https://goproxy.cn,direct & cd cmd && ./cmd + root: ./ + name: demo + description: demo + autoOpen: true diff --git a/res/0c84f27a-98cd-4196-a495-507da2d183df.png b/res/0c84f27a-98cd-4196-a495-507da2d183df.png new file mode 100644 index 0000000000000000000000000000000000000000..1968c9ea983b31d38cc07e7c7a66ffc70e9c2422 Binary files /dev/null and b/res/0c84f27a-98cd-4196-a495-507da2d183df.png differ diff --git a/res/0ed7aff0-0e4f-4e7e-804f-0053b61fb3d0.png b/res/0ed7aff0-0e4f-4e7e-804f-0053b61fb3d0.png new file mode 100644 index 0000000000000000000000000000000000000000..cc74ace65c4a0b441f935c9709e82acddce85200 Binary files /dev/null and b/res/0ed7aff0-0e4f-4e7e-804f-0053b61fb3d0.png differ diff --git a/res/3f8b879b-fa29-4dda-8e08-1f82cbd2d895.png b/res/3f8b879b-fa29-4dda-8e08-1f82cbd2d895.png new file mode 100644 index 0000000000000000000000000000000000000000..29d13545ce1d23625d4baebd69267b7b72558448 Binary files /dev/null and b/res/3f8b879b-fa29-4dda-8e08-1f82cbd2d895.png differ diff --git a/res/573949ca-9a6f-4359-8569-ddc4e1c53bff.png b/res/573949ca-9a6f-4359-8569-ddc4e1c53bff.png new file mode 100644 index 0000000000000000000000000000000000000000..b72a7c8b06ba1af0c0a0cdcfab850df8ae5eb7b8 Binary files /dev/null and b/res/573949ca-9a6f-4359-8569-ddc4e1c53bff.png differ diff --git a/res/626778da-42a6-4ece-aff9-e6baed8b3927.png b/res/626778da-42a6-4ece-aff9-e6baed8b3927.png new file mode 100644 index 0000000000000000000000000000000000000000..4b58463ec58de4a606adec34945efb63745a80bf Binary files /dev/null and b/res/626778da-42a6-4ece-aff9-e6baed8b3927.png differ diff --git a/res/6a8f64b9-e265-47d4-8b9a-348d74423894.png b/res/6a8f64b9-e265-47d4-8b9a-348d74423894.png new file mode 100644 index 0000000000000000000000000000000000000000..8f49c87c29ac5fe0620d85337a4adb788103b8cb Binary files /dev/null and b/res/6a8f64b9-e265-47d4-8b9a-348d74423894.png differ diff --git a/res/7517f346-880a-46bf-b8f7-477be62904d4.png b/res/7517f346-880a-46bf-b8f7-477be62904d4.png new file mode 100644 index 0000000000000000000000000000000000000000..44ad8e0a091daef57da9cf3d0823dc37b5c20b7c Binary files /dev/null and b/res/7517f346-880a-46bf-b8f7-477be62904d4.png differ diff --git a/res/98201d83-5d29-4b78-9668-4ccb95dda7f4.png b/res/98201d83-5d29-4b78-9668-4ccb95dda7f4.png new file mode 100644 index 0000000000000000000000000000000000000000..ec6d2a908f687db96a379e98bdb9ef03898977fc Binary files /dev/null and b/res/98201d83-5d29-4b78-9668-4ccb95dda7f4.png differ diff --git a/res/a2bcb499-3750-4d82-90e7-c5985967f782.png b/res/a2bcb499-3750-4d82-90e7-c5985967f782.png new file mode 100644 index 0000000000000000000000000000000000000000..1c41b90a0b1ff8c5f5a7b33cb2ab1e90ee14f270 Binary files /dev/null and b/res/a2bcb499-3750-4d82-90e7-c5985967f782.png differ diff --git a/res/d10505f4-e842-4017-90a2-3ade396a2ac8.png b/res/d10505f4-e842-4017-90a2-3ade396a2ac8.png new file mode 100644 index 0000000000000000000000000000000000000000..2b12700fe695161b53031396de46046f81455d59 Binary files /dev/null and b/res/d10505f4-e842-4017-90a2-3ade396a2ac8.png differ diff --git a/router/router.go b/router/router.go new file mode 100644 index 0000000000000000000000000000000000000000..e8587724cc13b57c2eaacfb4f0543a4c6d86d5df --- /dev/null +++ b/router/router.go @@ -0,0 +1,26 @@ +package router + +import ( + . "mock/controller" + "mock/middleware" + "net/http" + + "github.com/gin-gonic/gin" +) + +/* +InitRouter 路由初始化 +*/ +func InitRouter() *gin.Engine { + router := gin.Default() + // 加载 templates 文件夹下所有的 tmpl + router.LoadHTMLGlob("../templates/*") + router.StaticFS("/res", http.Dir("../res")) + router.GET("/", Index) + v1 := router.Group("/api") + v1.Use(middleware.CORSMiddleware()) + { + v1.Any("/GetImg", GetImg) + } + return router +} diff --git a/src/gitcode-ssh.png b/src/gitcode-ssh.png deleted file mode 100644 index e06b993f9d832683bd27b5b48ee82c238194c55f..0000000000000000000000000000000000000000 Binary files a/src/gitcode-ssh.png and /dev/null differ diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 81396591737232e64948e62a31f76d4d6d2b3e3c..0000000000000000000000000000000000000000 --- a/src/logo.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - 开发云logo备份@40x - - - - - - - \ No newline at end of file diff --git a/src/style.css b/src/style.css deleted file mode 100644 index 004b70af09694f2c90f0a500bf31fd69dba7b732..0000000000000000000000000000000000000000 --- a/src/style.css +++ /dev/null @@ -1,6 +0,0 @@ -.app{ - text-align: center; -} -.app img{ - margin-top: 32px; -} \ No newline at end of file diff --git "a/src/\345\205\245\347\276\244\344\272\214\347\273\264\347\240\201.jpg" "b/src/\345\205\245\347\276\244\344\272\214\347\273\264\347\240\201.jpg" deleted file mode 100644 index c8e954868c376d5e02c8d5aa6ff00f220c3d7e60..0000000000000000000000000000000000000000 Binary files "a/src/\345\205\245\347\276\244\344\272\214\347\273\264\347\240\201.jpg" and /dev/null differ diff --git a/templates/index.tmpl b/templates/index.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..355b919452b0fab9c5836ca184d30ddc49296cfb --- /dev/null +++ b/templates/index.tmpl @@ -0,0 +1,82 @@ + + + + + + + + + + + +
+
+ +
+ + + 水平方向 + 垂直方向 + 字体1 + 字体2 + Run + +
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/util/util.go b/util/util.go new file mode 100644 index 0000000000000000000000000000000000000000..bcb4514d56a8907e8e5330edbb8c365fc18294fe --- /dev/null +++ b/util/util.go @@ -0,0 +1,152 @@ +package util + +import ( + "flag" + "github.com/golang/freetype" + "image" + "image/color" + "image/png" + "io/ioutil" + "log" + . "mock/lib/font/config" + "os" +) + +// charset 中文文字 +// horV - H-横排,V-竖排 +// out 输出文件名 +// font 字体 +var ( + Char = flag.String("charset", "你好世界", "text (ZH)") + HorV = flag.String("horV", "H", "H | V") + Out = flag.String("out", "", "output file name") + Font = flag.String("font", "f1", "f1 | f2") +) + +func Generator(charset []string, outPath string, horV string, textFont TextFont) { + + // 打开背景图 + bgFile, err := os.OpenFile("../img/bg.png", os.O_RDONLY, 6) + if err != nil { + log.Fatal(err) + } + + defer bgFile.Close() + + // 解码 + i, err := png.Decode(bgFile) + if err != nil { + log.Fatal(err) + } + + // 图片的宽度 + srcWidth := 640 + // 图片的高度 + srcHeight := 640 + + if horV == "H" { + srcWidth = 640 * len(charset) + } + + if horV == "V" { + srcHeight = 640 * len(charset) + } + + imgFile, _ := os.Create(outPath) + defer imgFile.Close() + img := image.NewRGBA(image.Rect(0, 0, srcWidth, srcHeight)) + + if horV == "H" { + log.Println("横向生成,渲染背景...") + // 根据字符长度创建背景 + for index := 0; index < len(charset); index++ { + // 复制背景图 + for y := 0; y < srcHeight; y++ { + for x := index * 640; x < srcWidth; x++ { + if x < 640 { + img.Set(x, y, i.At(x, y)) + } else { + img.Set(x, y, i.At(x-index*640, y)) + } + } + } + } + } + + if horV == "V" { + log.Println("竖向生成,渲染背景...") + // 根据字符长度创建背景 + for index := 0; index < len(charset); index++ { + // 复制背景图 + for y := index * 640; y < srcHeight; y++ { + for x := 0; x < srcWidth; x++ { + if y < 640 { + img.Set(x, y, i.At(x, y)) + } else { + img.Set(x, y, i.At(x, y-index*640)) + } + } + } + } + } + + // 读取字体数据 + fontFileName := "../lib/font/" + textFont.FontName + fontBytes, err := ioutil.ReadFile(fontFileName) + log.Printf("加载字体:%s...", textFont.FontName) + if err != nil { + log.Fatal(err) + } + + // 载入字体数据 + font, err := freetype.ParseFont(fontBytes) + if err != nil { + log.Println("载入字体失败!", err) + } + f := freetype.NewContext() + // 设置分辨率 + f.SetDPI(100) + // 设置字体 + f.SetFont(font) + // 设置尺寸 + f.SetFontSize(textFont.FontSize) + f.SetClip(img.Bounds()) + // 设置输出的图片 + f.SetDst(img) + // 设置字体颜色(黑色) + f.SetSrc(image.NewUniform(color.Black)) + + if horV == "H" { + log.Println("开始绘制对联...") + // 绘制字符 + for index := 0; index < len(charset); index++ { + // 设置字体的位置 + pt := freetype.Pt(textFont.X+index*640, textFont.Y) + + _, err = f.DrawString(charset[index], pt) + if err != nil { + log.Fatal(err) + } + } + } + + if horV == "V" { + // 绘制字符 + for index := 0; index < len(charset); index++ { + // 设置字体的位置 + pt := freetype.Pt(textFont.X, textFont.Y+index*640) + + _, err = f.DrawString(charset[index], pt) + if err != nil { + log.Fatal(err) + } + } + } + + // 以png 格式写入文件作为输出 + err = png.Encode(imgFile, img) + if err != nil { + log.Fatal(err) + } + log.Println("Done.") +} \ No newline at end of file