From 8fb9d7f36b2757cbfe12a56c753efffeec77e227 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 19 Aug 2022 13:27:18 +0800 Subject: [PATCH] =?UTF-8?q?WebP=E5=8E=8B=E7=BC=A9Gif=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BF=87=E8=BD=AC=E6=8D=A2=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E5=B8=A7=EF=BC=8C=E5=B9=B6=E5=8F=AA=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=9C=80=E5=90=8E=E4=B8=80=E6=AC=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index ae9e047..630a306 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -1007,23 +1007,29 @@ func (this *HTTPWriter) finishWebP() { Exact: true, }) } else if gifImage != nil { - anim := gowebp.NewWebpAnimation(gifImage.Config.Width, gifImage.Config.Height, gifImage.LoopCount) + var anim = gowebp.NewWebpAnimation(gifImage.Config.Width, gifImage.Config.Height, gifImage.LoopCount) + anim.WebPAnimEncoderOptions.SetKmin(9) anim.WebPAnimEncoderOptions.SetKmax(17) defer anim.ReleaseMemory() - webpConfig := gowebp.NewWebpConfig() + var webpConfig = gowebp.NewWebpConfig() //webpConfig.SetLossless(1) webpConfig.SetQuality(f) var timeline = 0 - + var lastErr error for i, img := range gifImage.Image { err = anim.AddFrame(img, timeline, webpConfig) if err != nil { - break + // 有错误直接跳过 + lastErr = err + err = nil } timeline += gifImage.Delay[i] * 10 } + if lastErr != nil { + remotelogs.Error("HTTP_WRITER", "'"+this.req.URL()+"' encode webp failed: "+lastErr.Error()) + } if err == nil { err = anim.AddFrame(nil, timeline, webpConfig)