From 1310054121664f272c63d7f428ff4ec693662f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 22 Jul 2024 15:16:28 +0200 Subject: [PATCH] v0.0.488 fix wpdf with 16bpp images --- goextVersion.go | 4 ++-- wpdf/wpdfImage.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index cd3b1da..04b7716 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.487" +const GoextVersion = "0.0.488" -const GoextVersionTimestamp = "2024-07-18T17:45:56+0200" +const GoextVersionTimestamp = "2024-07-22T15:16:28+0200" diff --git a/wpdf/wpdfImage.go b/wpdf/wpdfImage.go index f26883f..9058f01 100644 --- a/wpdf/wpdfImage.go +++ b/wpdf/wpdfImage.go @@ -7,6 +7,7 @@ import ( "gogs.mikescher.com/BlackForestBytes/goext/langext" "image" "image/color" + "image/draw" "net/http" ) @@ -284,6 +285,13 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { } } + if dataimg.ColorModel() != color.RGBAModel && dataimg.ColorModel() != color.NRGBAModel { + // the image cannto be 16bpp or similar - otherwise fpdf errors out + dataImgRGBA := image.NewNRGBA(image.Rect(0, 0, dataimg.Bounds().Dx(), dataimg.Bounds().Dy())) + draw.Draw(dataImgRGBA, dataImgRGBA.Bounds(), dataimg, dataimg.Bounds().Min, draw.Src) + dataimg = dataImgRGBA + } + bfr, imgMime, err := imageext.EncodeImage(dataimg, compression) if err != nil { b.b.SetError(err)