From 2fa5233fa67598adf1efecee19ae3b756eb98dcf Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Wed, 14 Sep 2022 17:12:47 +0300 Subject: [PATCH] [#440] try to use the original image format when creating thumbs --- tools/filesystem/filesystem.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/filesystem/filesystem.go b/tools/filesystem/filesystem.go index a4f75ae2..414235ea 100644 --- a/tools/filesystem/filesystem.go +++ b/tools/filesystem/filesystem.go @@ -305,8 +305,15 @@ func (s *System) CreateThumb(originalKey string, thumbKey, thumbSize string) err return writerErr } + // try to detect the thumb format based on the original file name + // (fallbacks to png on error) + format, err := imaging.FormatFromFilename(thumbKey) + if err != nil { + format = imaging.PNG + } + // thumb encode (aka. upload) - if err := imaging.Encode(w, thumbImg, imaging.PNG); err != nil { + if err := imaging.Encode(w, thumbImg, format); err != nil { w.Close() return err }