增加chunk图片文件支持width和height

This commit is contained in:
zhangmingfeng
2018-07-05 10:34:17 +08:00
parent 77fc8c5914
commit 79d18c69b4
3 changed files with 32 additions and 14 deletions

View File

@@ -3,6 +3,8 @@ package images
import (
"path/filepath"
"strings"
"bytes"
"io"
)
/*
@@ -13,15 +15,15 @@ import (
* Call this function on any file uploaded to SeaweedFS
*
*/
func MaybePreprocessImage(filename string, data []byte, width, height int) (resized []byte, w int, h int) {
func MaybePreprocessImage(filename string, data []byte, width, height int) (resized io.ReadSeeker, w int, h int) {
ext := filepath.Ext(filename)
ext = strings.ToLower(ext)
switch ext {
case ".png", ".gif":
return Resized(ext, data, width, height, "")
return Resized(ext, bytes.NewReader(data), width, height, "")
case ".jpg", ".jpeg":
data = FixJpgOrientation(data)
return Resized(ext, data, width, height, "")
return Resized(ext, bytes.NewReader(data), width, height, "")
}
return data, 0, 0
return bytes.NewReader(data), 0, 0
}