aboutsummaryrefslogtreecommitdiff
path: root/weed/images/resizing.go
diff options
context:
space:
mode:
authorzhangmingfeng <zhangmf2008@126.com>2018-07-05 10:34:17 +0800
committerzhangmingfeng <zhangmf2008@126.com>2018-07-05 10:34:17 +0800
commit79d18c69b4ba68e6fb84893ff7b43027b4db5387 (patch)
treee99ad2cf4bd957aec720d56fc3769fc57a482c2a /weed/images/resizing.go
parent77fc8c59140537bb693ccf44c63e68626322b70e (diff)
downloadseaweedfs-79d18c69b4ba68e6fb84893ff7b43027b4db5387.tar.xz
seaweedfs-79d18c69b4ba68e6fb84893ff7b43027b4db5387.zip
增加chunk图片文件支持width和height
Diffstat (limited to 'weed/images/resizing.go')
-rw-r--r--weed/images/resizing.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/weed/images/resizing.go b/weed/images/resizing.go
index 0ea6b1777..ff0eff5e1 100644
--- a/weed/images/resizing.go
+++ b/weed/images/resizing.go
@@ -9,13 +9,14 @@ import (
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/disintegration/imaging"
+ "io"
)
-func Resized(ext string, data []byte, width, height int, mode string) (resized []byte, w int, h int) {
+func Resized(ext string, read io.ReadSeeker, width, height int, mode string) (resized io.ReadSeeker, w int, h int) {
if width == 0 && height == 0 {
- return data, 0, 0
+ return read, 0, 0
}
- srcImage, _, err := image.Decode(bytes.NewReader(data))
+ srcImage, _, err := image.Decode(read)
if err == nil {
bounds := srcImage.Bounds()
var dstImage *image.NRGBA
@@ -34,7 +35,7 @@ func Resized(ext string, data []byte, width, height int, mode string) (resized [
}
}
} else {
- return data, bounds.Dx(), bounds.Dy()
+ return read, bounds.Dx(), bounds.Dy()
}
var buf bytes.Buffer
switch ext {
@@ -45,9 +46,9 @@ func Resized(ext string, data []byte, width, height int, mode string) (resized [
case ".gif":
gif.Encode(&buf, dstImage, nil)
}
- return buf.Bytes(), dstImage.Bounds().Dx(), dstImage.Bounds().Dy()
+ return bytes.NewReader(buf.Bytes()), dstImage.Bounds().Dx(), dstImage.Bounds().Dy()
} else {
glog.Error(err)
}
- return data, 0, 0
+ return read, 0, 0
}