Chris Lu
11 years ago
6 changed files with 54 additions and 61 deletions
-
14go/filer/client_operations.go
-
39go/images/images.go
-
12go/weed/mount_std.go
-
1go/weed/weed_server/filer_server.go
-
20go/weed/weed_server/filer_server_handlers_api.go
-
29go/weed/weed_server/volume_server_handlers.go
@ -0,0 +1,39 @@ |
|||
package images |
|||
|
|||
import ( |
|||
"bytes" |
|||
"github.com/disintegration/imaging" |
|||
"image" |
|||
"image/gif" |
|||
"image/jpeg" |
|||
"image/png" |
|||
) |
|||
|
|||
func FixJpgOrientation() { |
|||
} |
|||
|
|||
func Resized(ext string, data []byte, width, height int) (resized []byte) { |
|||
if width == 0 && height == 0 { |
|||
return data |
|||
} |
|||
if srcImage, _, err := image.Decode(bytes.NewReader(data)); err == nil { |
|||
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) |
|||
} |
|||
return buf.Bytes() |
|||
} |
|||
return data |
|||
} |
@ -1,20 +0,0 @@ |
|||
package weed_server |
|||
|
|||
import ( |
|||
"net/http" |
|||
) |
|||
|
|||
func (fs *FilerServer) filerApiHandler(w http.ResponseWriter, r *http.Request) { |
|||
switch r.Method { |
|||
case "GET": |
|||
fs.GetOrHeadHandler(w, r, true) |
|||
case "HEAD": |
|||
fs.GetOrHeadHandler(w, r, false) |
|||
case "DELETE": |
|||
fs.DeleteHandler(w, r) |
|||
case "PUT": |
|||
fs.PostHandler(w, r) |
|||
case "POST": |
|||
fs.PostHandler(w, r) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue