From bfa8457e9517c9e8fda926e223264c72cd7fb132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 20 May 2024 00:07:33 +0200 Subject: [PATCH] v0.0.457 test --- goextVersion.go | 4 ++-- wpdf/wpdfImage.go | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index d3baf79..2166f4c 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.456" +const GoextVersion = "0.0.457" -const GoextVersionTimestamp = "2024-05-18T23:38:47+0200" +const GoextVersionTimestamp = "2024-05-20T00:07:33+0200" diff --git a/wpdf/wpdfImage.go b/wpdf/wpdfImage.go index f26883f..630f436 100644 --- a/wpdf/wpdfImage.go +++ b/wpdf/wpdfImage.go @@ -7,7 +7,9 @@ import ( "gogs.mikescher.com/BlackForestBytes/goext/langext" "image" "image/color" + "image/png" "net/http" + "os" ) type PDFImageRef struct { @@ -227,7 +229,7 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { reEncodePixelPerMM := 15.0 var imageFit *imageext.ImageFit = nil var fillColor color.Color = color.Transparent - compression := imageext.CompressionPNGSpeed + var compression *imageext.ImageCompresson = nil var crop *imageext.ImageCrop = nil for _, opt := range opts { @@ -243,14 +245,14 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { allowNegativePosition = langext.Coalesce(opt.allowNegativePosition, allowNegativePosition) imageFit = langext.CoalesceOpt(opt.imageFit, imageFit) fillColor = langext.Coalesce(opt.fillColor, fillColor) - compression = langext.Coalesce(opt.compression, compression) + compression = langext.CoalesceOpt(opt.compression, compression) reEncodePixelPerMM = langext.Coalesce(opt.reEncodePixelPerMM, reEncodePixelPerMM) crop = langext.CoalesceOpt(opt.crop, crop) } regName := img.Name - if imageFit != nil || fillColor != nil || crop != nil { + if imageFit != nil || fillColor != nil || crop != nil || compression != nil { var dataimg image.Image if img.Image != nil { @@ -261,6 +263,16 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { b.b.SetError(err) return } + img.Image = langext.Ptr(dataimg) + } + + _ = os.WriteFile("/tmp/a.png", img.Bin, 0755) + + { + bfr := bytes.Buffer{} + enc := &png.Encoder{CompressionLevel: png.NoCompression} + _ = enc.Encode(&bfr, dataimg) + _ = os.WriteFile("/tmp/b.png", img.Bin, 0755) } if crop != nil { @@ -284,7 +296,7 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { } } - bfr, imgMime, err := imageext.EncodeImage(dataimg, compression) + bfr, imgMime, err := imageext.EncodeImage(dataimg, langext.Coalesce(compression, imageext.CompressionPNGSpeed)) if err != nil { b.b.SetError(err) return @@ -301,6 +313,8 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) { imageType = "GIF" } + _ = os.WriteFile("/tmp/c.png", bfr.Bytes(), 0755) + b.b.RegisterImageOptionsReader(regName, gofpdf.ImageOptions{ImageType: imageType}, &bfr) }