fusenapi/utils/image/image_size.go

29 lines
689 B
Go
Raw Normal View History

2023-06-01 07:32:28 +00:00
package image
// 定义尺寸规则
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
// 裁剪尺寸阶梯
var newSizeArray = []uint32{200, 400, 600, 800}
func GetCurrentSize(clientSize uint32) uint32 {
lenNewSize := len(newSizeArray)
//大于最大尺寸则返回规则最大尺寸
if clientSize >= newSizeArray[lenNewSize-1] {
return newSizeArray[lenNewSize-1]
}
//小于最小尺寸则返回规则最小尺寸
if clientSize < newSizeArray[0] {
return clientSize
}
for k, v := range newSizeArray {
if v == clientSize {
return v
}
if clientSize > v && k < lenNewSize-1 && clientSize < newSizeArray[k+1] {
return newSizeArray[k+1]
}
}
return clientSize
}