提交 919d103f 编写于 作者: 6 62deab431cad725575ce629a

init

上级 e63fb81c
文件已添加
package main
import (
"mock/router"
)
func main() {
r := router.InitRouter()
r.Run(":8080")
}
\ No newline at end of file
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,
})
}
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
)
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=
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="src/style.css">
</head>
<body>
<div class="app">
<img src="src/logo.svg" width="100px">
<h1>欢迎使用 Cloud IDE</h1>
官网:<a href="https://ide.csdn.net" target="_blank">https://ide.csdn.net</a>
</div>
</body>
</html>
\ No newline at end of file
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}
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
{
"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"
}
}
# 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
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
}
<?xml version="1.0" encoding="UTF-8"?>
<svg width="37px" height="28px" viewBox="0 0 37 28" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>开发云logo备份@40x</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="开发云logo备份@40x" transform="translate(2.000000, 2.000000)" stroke="#1890FF">
<path d="M22.8925411,9.29032948 L22.8925411,6.7248501 C22.8925411,3.01081795 19.8817231,-1.77635684e-15 16.167691,-1.77635684e-15 C12.4536588,-1.77635684e-15 9.44284085,3.01081795 9.44284085,6.7248501 L9.44284085,7.87271787 L9.44284085,7.87271787 L7.66157921,7.87271787 C3.43020585,7.87271787 0,11.3029237 0,15.5342971 C0,19.7656704 3.43020585,23.1958763 7.66157921,23.1958763 L23.6762383,23.1958763 L23.6762383,23.1958763" id="路径-28" stroke-width="4" stroke-linecap="round"></path>
<path d="M33.2652638,20.4086185 C33.0827033,20.2352897 32.8345087,20.1392132 32.5943359,20.1433691 C32.3478429,20.1482585 32.1246865,20.2509357 31.9659488,20.4335544 C30.544846,22.0690553 28.0684903,22.2455623 27.0696344,22.2455623 C25.2163178,22.2455623 23.798132,21.7732472 22.8544575,20.8423074 C21.9579423,19.9578168 21.4880498,18.6552834 21.4571774,16.9706441 C21.3852228,13.0654885 23.5839699,9.02587465 27.388082,9.02587465 C29.2051781,9.02587465 30.6155851,10.3220519 31.1374989,10.8794423 C31.3188438,11.0728177 31.5699556,11.1842958 31.8273877,11.1850292 C32.0860352,11.1921188 32.3245063,11.0764847 32.4864041,10.8845762 L32.6344458,10.7085581 C32.938308,10.3486991 33.0754106,9.88371809 33.0199862,9.39991297 C32.9645617,8.91195187 32.7209857,8.46579505 32.3347161,8.14431767 C31.4027098,7.36812705 29.8184937,6.44329897 27.5648083,6.44329897 C25.2231243,6.44329897 22.9103681,7.52654327 21.2191925,9.41555902 C19.4426923,11.4001623 18.4936698,14.1025281 18.5476357,17.0241829 C18.5906626,19.3679119 19.3554231,21.3390694 20.7597528,22.7249669 C22.2681249,24.2132972 24.4785403,25 27.152528,25 C30.2896017,25 32.2338338,24.066371 33.3124232,23.2830908 C33.7300514,22.9799486 33.9801908,22.5020108 33.9989087,21.9720009 C34.0173836,21.4397908 33.8005475,20.9180929 33.404068,20.5408765 L33.2652638,20.4086185 Z" id="Fill-9457" fill="#1890FF" fill-rule="nonzero"></path>
</g>
</g>
</svg>
\ No newline at end of file
.app{
text-align: center;
}
.app img{
margin-top: 32px;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
<div class="demo-image__lazy" style="margin-top:30px;">
<el-image src="../res/3f8b879b-fa29-4dda-8e08-1f82cbd2d895.png"></el-image>
</div>
<el-input placeholder="请输入内容" v-model="input" clearable>
</el-input>
<el-radio v-model="horV" label="H">水平方向</el-radio>
<el-radio v-model="horV" label="V">垂直方向</el-radio>
<el-radio v-model="font" label="font1">字体1</el-radio>
<el-radio v-model="font" label="font2">字体2</el-radio>
<el-button style="margin-left: 10px;margin-top:30px;" size="small" type="success" @click="submitUpload"
v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="拼命加载中">Run
</el-button>
<div class="demo-image__lazy" style="margin-top:30px;">
<el-image v-for="url in urls" :key="url" :src="url" lazy></el-image>
</div>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
horV: 'H',
font: 'font1',
input: '',
urls: [],
fullscreenLoading: false
};
},
methods: {
// 提交表单
submitUpload() {
if (this.input.length > 0) {
console.log(this.input, this.horV, this.font);
let formdata = {
worlds: this.input,
horV: this.horV,
font: this.font,
};
this.fullscreenLoading = true;
var that = this;
axios({
url: '/api/GetImg',
method: 'post',
data: formdata,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(function (response) {
console.log('success');
console.log(response);
that.urls = response.data.urls;
that.fullscreenLoading = false;
})
.catch(function (error) {
console.log('error');
console.log(error);
});
}
}
}
})
</script>
</html>
\ No newline at end of file
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册