mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
WebP resize support
This commit is contained in:
parent
a337b844ec
commit
7ab9160ee1
|
@ -17,7 +17,7 @@ func MaybePreprocessImage(filename string, data []byte, width, height int) (resi
|
|||
ext := filepath.Ext(filename)
|
||||
ext = strings.ToLower(ext)
|
||||
switch ext {
|
||||
case ".png", ".gif":
|
||||
case ".png", ".gif", ".webp":
|
||||
return Resized(ext, data, width, height)
|
||||
case ".jpg", ".jpeg":
|
||||
data = FixJpgOrientation(data)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"github.com/chai2010/webp"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/disintegration/imaging"
|
||||
|
@ -37,6 +38,8 @@ func Resized(ext string, data []byte, width, height int) (resized []byte, w int,
|
|||
jpeg.Encode(&buf, dstImage, nil)
|
||||
case ".gif":
|
||||
gif.Encode(&buf, dstImage, nil)
|
||||
case ".webp":
|
||||
webp.Encode(&buf, dstImage, &webp.Options{Quality: 70})
|
||||
}
|
||||
return buf.Bytes(), dstImage.Bounds().Dx(), dstImage.Bounds().Dy()
|
||||
} else {
|
||||
|
|
|
@ -136,7 +136,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
}
|
||||
}
|
||||
if ext == ".png" || ext == ".jpg" || ext == ".gif" {
|
||||
if ext == ".png" || ext == ".jpg" || ext == ".gif"|| ext == ".webp" {
|
||||
width, height := 0, 0
|
||||
if r.FormValue("width") != "" {
|
||||
width, _ = strconv.Atoi(r.FormValue("width"))
|
||||
|
|
Loading…
Reference in a new issue