From 2c0dd15222185ede93c285838e6931b076884f71 Mon Sep 17 00:00:00 2001 From: Nova Kwok Date: Thu, 15 Jun 2023 15:28:59 +0800 Subject: [PATCH] Now we support animated GIF images (#232) * Now we support animated GIF images * Fix CI * Update runtime image --- Dockerfile | 4 ++-- README.md | 4 ++-- config.go | 4 ++-- config.json | 2 +- encoder_test.go | 2 ++ webp-server_test.go | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 10a79a7..052a98a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20 as builder +FROM golang:1.20-bookworm as builder ARG IMG_PATH=/opt/pics ARG EXHAUST_PATH=/opt/exhaust @@ -12,7 +12,7 @@ RUN cd /build && sed -i "s|.\/pics|${IMG_PATH}|g" config.json \ && sed -i 's/127.0.0.1/0.0.0.0/g' config.json \ && go build -ldflags="-s -w" -o webp-server . -FROM debian:bullseye-slim +FROM debian:bookworm-slim RUN apt update && apt install --no-install-recommends libvips ca-certificates libjemalloc2 libtcmalloc-minimal4 -y && rm -rf /var/lib/apt/lists/* && rm -rf /var/cache/apt/archives/* diff --git a/README.md b/README.md index b19003b..9ff0d5e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This is a Server based on Golang, which allows you to serve WebP images on the fly. It will convert `jpg,jpeg,png` files by default, this can be customized by editing the `config.json`.. -* currently supported image format: JPEG, PNG, BMP, GIF(static image for now) +* currently supported image format: JPEG, PNG, BMP, GIF > e.g When you visit `https://your.website/pics/tsuki.jpg`,it will serve as `image/webp` format without changing the URL. > @@ -65,7 +65,7 @@ The default `config.json` may look like this. "QUALITY": "80", "IMG_PATH": "/path/to/pics", "EXHAUST_PATH": "/path/to/exhaust", - "ALLOWED_TYPES": ["jpg","png","jpeg","bmp"], + "ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif"], "ENABLE_AVIF": false, "ENABLE_EXTRA_PARAMS": false } diff --git a/config.go b/config.go index d500e82..ada1855 100644 --- a/config.go +++ b/config.go @@ -31,7 +31,7 @@ var ( prefetch, proxyMode bool remoteRaw = "remote-raw" config Config - version = "0.8.4" + version = "0.9.0" ) const ( @@ -42,7 +42,7 @@ const ( "QUALITY": "80", "IMG_PATH": "./pics", "EXHAUST_PATH": "./exhaust", - "ALLOWED_TYPES": ["jpg","png","jpeg","bmp"], + "ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif"], "ENABLE_AVIF": false, "ENABLE_EXTRA_PARAMS": false }` diff --git a/config.json b/config.json index 7f09d54..63a4012 100644 --- a/config.json +++ b/config.json @@ -4,7 +4,7 @@ "QUALITY": "80", "IMG_PATH": "./pics", "EXHAUST_PATH": "./exhaust", - "ALLOWED_TYPES": ["jpg","png","jpeg","bmp"], + "ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif"], "ENABLE_AVIF": false, "ENABLE_EXTRA_PARAMS": false } \ No newline at end of file diff --git a/encoder_test.go b/encoder_test.go index 51e2b3e..6cfc911 100644 --- a/encoder_test.go +++ b/encoder_test.go @@ -99,6 +99,8 @@ func TestWebPEncoder(t *testing.T) { func TestAnimatedGIFWithWebPEncoder(t *testing.T) { runEncoder(t, "./pics/gif-animated.gif", dest) _ = os.Remove(dest) + runEncoder(t, "./pics/no.gif", dest) + _ = os.Remove(dest) } func TestAvifEncoder(t *testing.T) { diff --git a/webp-server_test.go b/webp-server_test.go index 4b4ef27..316dda2 100644 --- a/webp-server_test.go +++ b/webp-server_test.go @@ -20,7 +20,7 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, "3333", c.Port) assert.Equal(t, 80, c.Quality) assert.Equal(t, "./pics", c.ImgPath) - assert.Equal(t, []string{"jpg", "png", "jpeg", "bmp"}, c.AllowedTypes) + assert.Equal(t, []string{"jpg", "png", "jpeg", "bmp", "gif"}, c.AllowedTypes) } func TestDeferInit(t *testing.T) {