mirror of
https://github.com/axllent/mailpit.git
synced 2026-03-03 02:57:01 +00:00
Fix: Avoid error 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).
This commit is contained in:
@@ -76,13 +76,14 @@ func Thumbnail(w http.ResponseWriter, r *http.Request) {
|
|||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
foo := bufio.NewWriter(&b)
|
foo := bufio.NewWriter(&b)
|
||||||
|
|
||||||
var dstImageFill *image.NRGBA
|
var temp image.Image
|
||||||
|
|
||||||
if img.Bounds().Dx() < thumbWidth || img.Bounds().Dy() < thumbHeight {
|
if img.Bounds().Dx() < thumbWidth || img.Bounds().Dy() < thumbHeight {
|
||||||
dstImageFill = imaging.Fit(img, thumbWidth, thumbHeight, imaging.Lanczos).(*image.NRGBA)
|
temp = imaging.Fit(img, thumbWidth, thumbHeight, imaging.Lanczos)
|
||||||
} else {
|
} else {
|
||||||
dstImageFill = imaging.Fill(img, thumbWidth, thumbHeight, imaging.Center, imaging.Lanczos).(*image.NRGBA)
|
temp = imaging.Fill(img, thumbWidth, thumbHeight, imaging.Center, imaging.Lanczos)
|
||||||
}
|
}
|
||||||
|
dstImageFill := imaging.Clone(temp)
|
||||||
|
|
||||||
// create white image and paste image over the top
|
// create white image and paste image over the top
|
||||||
// preventing black backgrounds for transparent GIF/PNG images
|
// preventing black backgrounds for transparent GIF/PNG images
|
||||||
dst := imaging.New(thumbWidth, thumbHeight, color.White)
|
dst := imaging.New(thumbWidth, thumbHeight, color.White)
|
||||||
|
|||||||
Reference in New Issue
Block a user