Skip to content

Commit a57b0df

Browse files
committed
Fix: Fix panic on image type assertion in thumbnail generation
Use imaging.Clone to ensure the image is always *image.NRGBA, preventing panics when decoding non-NRGBA images (e.g., JPEGs as *image.YCbCr).
1 parent cf64a8e commit a57b0df

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

server/apiv1/thumbnails.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ func Thumbnail(w http.ResponseWriter, r *http.Request) {
7676
var b bytes.Buffer
7777
foo := bufio.NewWriter(&b)
7878

79-
var dstImageFill *image.NRGBA
80-
79+
var temp image.Image
8180
if img.Bounds().Dx() < thumbWidth || img.Bounds().Dy() < thumbHeight {
82-
dstImageFill = imaging.Fit(img, thumbWidth, thumbHeight, imaging.Lanczos).(*image.NRGBA)
81+
temp = imaging.Fit(img, thumbWidth, thumbHeight, imaging.Lanczos)
8382
} else {
84-
dstImageFill = imaging.Fill(img, thumbWidth, thumbHeight, imaging.Center, imaging.Lanczos).(*image.NRGBA)
83+
temp = imaging.Fill(img, thumbWidth, thumbHeight, imaging.Center, imaging.Lanczos)
8584
}
85+
dstImageFill := imaging.Clone(temp)
86+
8687
// create white image and paste image over the top
8788
// preventing black backgrounds for transparent GIF/PNG images
8889
dst := imaging.New(thumbWidth, thumbHeight, color.White)

0 commit comments

Comments
 (0)