Skip to content

Commit

Permalink
ref: only try building animated thumbnail for animated formats
Browse files Browse the repository at this point in the history
This commit ensures that we only try to build animated thumbnails with
lilliput for image formats that support animation. In the other cases,
we immediately build the thumbnail using govips.
  • Loading branch information
leon-richardt committed Oct 3, 2022
1 parent 915732a commit 0e256b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/resolvers/default/thumbnail_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ func (l *ThumbnailLoader) Load(ctx context.Context, urlString string, r *http.Re
}

var image []byte
tryAnimatedThumb := l.enableLilliput && thumbnail.IsAnimatedThumbnailType(contentType)

// attempt building an animated image
if l.enableLilliput {
if tryAnimatedThumb {
image, err = thumbnail.BuildAnimatedThumbnail(inputBuf, resp)
}

// fallback to static image if animated image building failed or is disabled
if !l.enableLilliput || err != nil {
if !tryAnimatedThumb || err != nil {
if err != nil {
log.Errorw("Error trying to build animated thumbnail, falling back to static thumbnail building",
"error", err)
Expand Down
5 changes: 5 additions & 0 deletions pkg/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

var (
supportedThumbnails = []string{"image/jpeg", "image/png", "image/gif", "image/webp"}
animatedThumbnails = []string{"image/gif", "image/webp"}

cfg config.APIConfig
)
Expand All @@ -19,3 +20,7 @@ func IsSupportedThumbnail(contentType string) bool {

return false
}

func IsAnimatedThumbnailType(contentType string) bool {
return utils.Contains(animatedThumbnails, contentType)
}

0 comments on commit 0e256b1

Please sign in to comment.