@@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"strconv"
+ "strings"
"time"
)
@@ -255,8 +256,17 @@ func GetActivityShareImg(c *gin.Context) {
func calcuDrawXandY(drawText string, fontSize, canvasLength, canvasWidth int) (x, y, newSize int, err error) {
// y轴取画布宽度的一半
y = canvasWidth / 2
- // 文字所占总宽度
- lenText := len(drawText)
+ // 拆分文字计算总宽度
+ lenText := 0
+ strArr := strings.Split(drawText, "")
+ for _, str := range strArr {
+ if len(str) == 1 {
+ // 将字母符号算作2个长度
+ lenText += 2
+ } else {
+ lenText += 3
+ }
textUnit := float64(lenText) / 3
textWidth := int(textUnit * float64(fontSize))
// x轴上的起点位置