2023-06-01 07:32:28 +00:00
|
|
|
package image
|
|
|
|
|
2023-06-06 11:21:07 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fusenapi/constants"
|
|
|
|
"fusenapi/model"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-06-01 07:32:28 +00:00
|
|
|
// 定义尺寸规则
|
|
|
|
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
|
|
|
|
|
|
|
|
// 裁剪尺寸阶梯
|
|
|
|
var newSizeArray = []uint32{200, 400, 600, 800}
|
|
|
|
|
2023-06-06 11:21:07 +00:00
|
|
|
// 获取合适尺寸
|
2023-06-01 07:32:28 +00:00
|
|
|
func GetCurrentSize(clientSize uint32) uint32 {
|
|
|
|
lenNewSize := len(newSizeArray)
|
|
|
|
//大于最大尺寸则返回规则最大尺寸
|
|
|
|
if clientSize >= newSizeArray[lenNewSize-1] {
|
|
|
|
return newSizeArray[lenNewSize-1]
|
|
|
|
}
|
|
|
|
//小于最小尺寸则返回规则最小尺寸
|
2023-06-02 04:29:13 +00:00
|
|
|
if clientSize <= newSizeArray[0] {
|
2023-06-02 02:08:22 +00:00
|
|
|
return newSizeArray[0]
|
2023-06-01 07:32:28 +00:00
|
|
|
}
|
2023-06-02 02:08:22 +00:00
|
|
|
for _, v := range newSizeArray {
|
|
|
|
if v >= clientSize {
|
2023-06-01 07:32:28 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return clientSize
|
|
|
|
}
|
2023-06-06 11:21:07 +00:00
|
|
|
|
|
|
|
// 千人前面图像拼接
|
|
|
|
type ThousandFaceImageFormatReq struct {
|
|
|
|
Size int
|
|
|
|
IsThousandFace int
|
|
|
|
Cover string
|
|
|
|
CoverImg string
|
|
|
|
CoverDefault string
|
|
|
|
ProductId int64
|
|
|
|
UserInfo model.FsUser
|
|
|
|
}
|
|
|
|
|
|
|
|
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
|
|
|
if req.Size > 0 {
|
|
|
|
coverSlice := strings.Split(req.Cover, ".")
|
|
|
|
coverImgSlice := strings.Split(req.CoverImg, ".")
|
|
|
|
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
|
|
|
|
req.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
|
|
|
req.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
|
|
|
}
|
|
|
|
//千人千面处理
|
|
|
|
if req.IsThousandFace == 1 {
|
|
|
|
req.Cover = ""
|
|
|
|
req.CoverDefault = req.CoverImg
|
|
|
|
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
|
|
|
|
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserInfo.Id, req.UserInfo.Id, req.ProductId, time.Now().Unix())
|
|
|
|
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|