Skip to content

Commit

Permalink
[pocketbase#440] try to use the original image format when creating t…
Browse files Browse the repository at this point in the history
…humbs
  • Loading branch information
ganigeorgiev committed Sep 14, 2022
1 parent 030dfc2 commit 2fa5233
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tools/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2fa5233

Please sign in to comment.