mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
add bmp and gif support.
gif support is not perfect, need animated webp
This commit is contained in:
parent
2fa8db6b02
commit
102cba7f4f
12
config.json
12
config.json
@ -2,7 +2,13 @@
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": "3333",
|
||||
"QUALITY": "80",
|
||||
"IMG_PATH": "/path/to/pics",
|
||||
"EXHAUST_PATH": "/path/to/exhaust",
|
||||
"ALLOWED_TYPES": ["jpg","png","jpeg"]
|
||||
"IMG_PATH": "/Users/benny/goLandProject/webp_server_go/pics",
|
||||
"EXHAUST_PATH": "",
|
||||
"ALLOWED_TYPES": [
|
||||
"jpg",
|
||||
"png",
|
||||
"jpeg",
|
||||
"bmp",
|
||||
"gif"
|
||||
]
|
||||
}
|
||||
|
1
go.mod
1
go.mod
@ -5,4 +5,5 @@ go 1.13
|
||||
require (
|
||||
github.com/chai2010/webp v1.1.0
|
||||
github.com/gofiber/fiber v1.4.0
|
||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1
|
||||
)
|
||||
|
@ -7,7 +7,9 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"golang.org/x/image/bmp"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
@ -84,10 +86,12 @@ func webpEncoder(p1, p2 string, quality float32, Log bool, c chan int) (err erro
|
||||
img, _ = jpeg.Decode(bytes.NewReader(data))
|
||||
} else if strings.Contains(contentType, "png") {
|
||||
img, _ = png.Decode(bytes.NewReader(data))
|
||||
} else if strings.Contains(contentType, "bmp") {
|
||||
img, _ = bmp.Decode(bytes.NewReader(data))
|
||||
} else if strings.Contains(contentType, "gif") {
|
||||
// TODO: need to support animated webp
|
||||
img, _ = gif.Decode(bytes.NewReader(data))
|
||||
}
|
||||
// TODO should we add bmp and tiff support? Need more packages.
|
||||
// import "golang.org/x/image/bmp"
|
||||
// import "golang.org/x/image/tiff"
|
||||
|
||||
if img == nil {
|
||||
msg := "image file " + path.Base(p1) + " is corrupted or not supported"
|
||||
|
Loading…
x
Reference in New Issue
Block a user