feat: 添加查bl图命令以获取最新分数截图,并优化头像处理逻辑,使用新的图片缩放方法
This commit is contained in:
@@ -110,8 +110,8 @@ func ResizeImageByMaxWidth(imagePath string, maxWidth uint) (outputPath string,
|
||||
}
|
||||
}
|
||||
|
||||
// ResizeImageByMaxHeight 按最大高度缩放图片,保持宽高比
|
||||
func ResizeImageByMaxHeight(imagePath string, maxHeight uint) (outputPath string, err error) {
|
||||
// ResizeImageByMaxHeight2File 按最大高度缩放图片,保持宽高比
|
||||
func ResizeImageByMaxHeight2File(imagePath string, maxHeight uint) (outputPath string, err error) {
|
||||
// 打开源图片文件
|
||||
file, err := os.Open(imagePath)
|
||||
if err != nil {
|
||||
@@ -160,6 +160,39 @@ func ResizeImageByMaxHeight(imagePath string, maxHeight uint) (outputPath string
|
||||
}
|
||||
}
|
||||
|
||||
func ResizeImageByMaxHeight2Image(imagePath string, maxHeight uint) (output image.Image, err error) {
|
||||
// 打开源图片文件
|
||||
file, err := os.Open(imagePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// 解码图片
|
||||
var img image.Image
|
||||
var decodeErr error
|
||||
|
||||
ext := strings.ToLower(filepath.Ext(imagePath))
|
||||
switch ext {
|
||||
case ".jpg", ".jpeg":
|
||||
img, decodeErr = jpeg.Decode(file)
|
||||
case ".png":
|
||||
img, decodeErr = png.Decode(file)
|
||||
default:
|
||||
return nil, errors.New("unsupported image format")
|
||||
}
|
||||
|
||||
if decodeErr != nil {
|
||||
return nil, decodeErr
|
||||
}
|
||||
|
||||
// 计算缩放后的尺寸,保持宽高比
|
||||
// 传入0作为宽度,resize包会自动计算等比例的宽度
|
||||
resized := resize.Resize(0, maxHeight, img, resize.Lanczos3)
|
||||
|
||||
return resized, nil
|
||||
}
|
||||
|
||||
func GetResizedIamgePathByOrgPath(orgPath string) string {
|
||||
ext := strings.ToLower(filepath.Ext(orgPath))
|
||||
return strings.TrimSuffix(orgPath, ext) + "_resized" + ext
|
||||
|
||||
Reference in New Issue
Block a user