aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
Diffstat (limited to 'go')
-rw-r--r--go/weed/weed_server/volume_server_handlers.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/go/weed/weed_server/volume_server_handlers.go b/go/weed/weed_server/volume_server_handlers.go
index e2fd6e6f9..3c94a75f1 100644
--- a/go/weed/weed_server/volume_server_handlers.go
+++ b/go/weed/weed_server/volume_server_handlers.go
@@ -1,11 +1,17 @@
package weed_server
import (
+ "bytes"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/stats"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/topology"
+ "github.com/disintegration/imaging"
+ "image"
+ "image/gif"
+ "image/jpeg"
+ "image/png"
"mime"
"net/http"
"strconv"
@@ -118,6 +124,36 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
}
}
}
+ if ext == ".png" || ext == ".jpg" || ext == ".gif" {
+ if srcImage, _, err := image.Decode(bytes.NewReader(n.Data)); err == nil {
+ width, height := 0, 0
+ if r.FormValue("width") != "" {
+ width, _ = strconv.Atoi(r.FormValue("width"))
+ }
+ if r.FormValue("height") != "" {
+ height, _ = strconv.Atoi(r.FormValue("height"))
+ }
+ if width != 0 || height != 0 {
+ bounds := srcImage.Bounds()
+ var dstImage *image.NRGBA
+ if width == height && bounds.Dx() != bounds.Dy() {
+ dstImage = imaging.Thumbnail(srcImage, width, height, imaging.Lanczos)
+ } else {
+ dstImage = imaging.Resize(srcImage, width, height, imaging.Lanczos)
+ }
+ var buf bytes.Buffer
+ switch ext {
+ case ".png":
+ png.Encode(&buf, dstImage)
+ case ".jpg":
+ jpeg.Encode(&buf, dstImage, nil)
+ case ".gif":
+ gif.Encode(&buf, dstImage, nil)
+ }
+ n.Data = buf.Bytes()
+ }
+ }
+ }
w.Header().Set("Content-Length", strconv.Itoa(len(n.Data)))
if isGetMethod {
if _, e = w.Write(n.Data); e != nil {