SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
增加chunk图片文件支持width和height
zhangmingfeng79d18c69b4ba
diff --git a/weed/images/preprocess.go b/weed/images/preprocess.goindex 56f14eaa41..0cfb66c6b2 100644--- a/weed/images/preprocess.go+++ b/weed/images/preprocess.go@@ -3,6 +3,8 @@ package imagesimport ("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}diff --git a/weed/images/resizing.go b/weed/images/resizing.goindex 0ea6b1777a..ff0eff5e10 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.Bufferswitch 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}diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.goindex b784dd60e3..734291a36e 100644--- a/weed/server/volume_server_handlers_read.go+++ b/weed/server/volume_server_handlers_read.go@@ -135,7 +135,8 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)}}}- if ext == ".png" || ext == ".jpg" || ext == ".gif" {+ var rs io.ReadSeeker+ if ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" {width, height := 0, 0if r.FormValue("width") != "" {width, _ = strconv.Atoi(r.FormValue("width"))@@ -143,10 +144,10 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)if r.FormValue("height") != "" {height, _ = strconv.Atoi(r.FormValue("height"))}- n.Data, _, _ = images.Resized(ext, n.Data, width, height, r.FormValue("mode"))+ rs, _, _ = images.Resized(ext, bytes.NewReader(n.Data), width, height, r.FormValue("mode"))}- if e := writeResponseContent(filename, mtype, bytes.NewReader(n.Data), w, r); e != nil {+ if e := writeResponseContent(filename, mtype, rs, w, r); e != nil {glog.V(2).Infoln("response write error:", e)}}@@ -164,6 +165,9 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string,if fileName == "" && chunkManifest.Name != "" {fileName = chunkManifest.Name}++ ext := path.Ext(fileName)+mType := ""if chunkManifest.Mime != "" {mt := chunkManifest.Mime@@ -179,7 +183,18 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string,Master: vs.GetMaster(),}defer chunkedFileReader.Close()- if e := writeResponseContent(fileName, mType, chunkedFileReader, w, r); e != nil {+ var rs io.ReadSeeker+ if ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" {+ width, height := 0, 0+ if r.FormValue("width") != "" {+ width, _ = strconv.Atoi(r.FormValue("width"))+ }+ if r.FormValue("height") != "" {+ height, _ = strconv.Atoi(r.FormValue("height"))+ }+ rs, _, _ = images.Resized(ext, chunkedFileReader, width, height, r.FormValue("mode"))+ }+ if e := writeResponseContent(fileName, mType, rs, w, r); e != nil {glog.V(2).Infoln("response write error:", e)}return true