fix: make sure generating blur hashes for bmp, tiff and webp images works

This commit is contained in:
kolaente 2022-08-15 23:37:05 +02:00
parent 3ccc6365a6
commit 8bf0f8bb57
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 11 additions and 2 deletions

View file

@ -17,6 +17,7 @@
package migration package migration
import ( import (
"errors"
"image" "image"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
@ -64,9 +65,12 @@ func init() {
} }
src, _, err := image.Decode(bgFile.File) src, _, err := image.Decode(bgFile.File)
if err != nil { if err != nil && !errors.Is(err, image.ErrFormat) {
return err return err
} }
if err != nil && errors.Is(err, image.ErrFormat) {
log.Warningf("Could not generate a blur hash of list %d's background image: %s", l.ID, err)
}
dst := image.NewRGBA(image.Rect(0, 0, 32, 32)) dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
draw.NearestNeighbor.Scale(dst, dst.Rect, src, src.Bounds(), draw.Over, nil) draw.NearestNeighbor.Scale(dst, dst.Rect, src, src.Bounds(), draw.Over, nil)

View file

@ -17,10 +17,15 @@
package handler package handler
import ( import (
"image"
_ "image/gif" // To make sure the decoder used for generating blurHashes recognizes gifs _ "image/gif" // To make sure the decoder used for generating blurHashes recognizes gifs
_ "image/jpeg" // To make sure the decoder used for generating blurHashes recognizes jpgs _ "image/jpeg" // To make sure the decoder used for generating blurHashes recognizes jpgs
_ "image/png" // To make sure the decoder used for generating blurHashes recognizes pngs _ "image/png" // To make sure the decoder used for generating blurHashes recognizes pngs
_ "golang.org/x/image/bmp" // To make sure the decoder used for generating blurHashes recognizes bmps
_ "golang.org/x/image/tiff" // To make sure the decoder used for generating blurHashes recognizes tiffs
_ "golang.org/x/image/webp" // To make sure the decoder used for generating blurHashes recognizes tiffs
"image"
"io" "io"
"net/http" "net/http"
"strconv" "strconv"