v0.0.457 test
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m38s

This commit is contained in:
Mike Schwörer 2024-05-20 00:07:33 +02:00
parent 70106733d9
commit bfa8457e95
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,5 @@
package goext 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"

View File

@ -7,7 +7,9 @@ import (
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"image" "image"
"image/color" "image/color"
"image/png"
"net/http" "net/http"
"os"
) )
type PDFImageRef struct { type PDFImageRef struct {
@ -227,7 +229,7 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) {
reEncodePixelPerMM := 15.0 reEncodePixelPerMM := 15.0
var imageFit *imageext.ImageFit = nil var imageFit *imageext.ImageFit = nil
var fillColor color.Color = color.Transparent var fillColor color.Color = color.Transparent
compression := imageext.CompressionPNGSpeed var compression *imageext.ImageCompresson = nil
var crop *imageext.ImageCrop = nil var crop *imageext.ImageCrop = nil
for _, opt := range opts { for _, opt := range opts {
@ -243,14 +245,14 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) {
allowNegativePosition = langext.Coalesce(opt.allowNegativePosition, allowNegativePosition) allowNegativePosition = langext.Coalesce(opt.allowNegativePosition, allowNegativePosition)
imageFit = langext.CoalesceOpt(opt.imageFit, imageFit) imageFit = langext.CoalesceOpt(opt.imageFit, imageFit)
fillColor = langext.Coalesce(opt.fillColor, fillColor) fillColor = langext.Coalesce(opt.fillColor, fillColor)
compression = langext.Coalesce(opt.compression, compression) compression = langext.CoalesceOpt(opt.compression, compression)
reEncodePixelPerMM = langext.Coalesce(opt.reEncodePixelPerMM, reEncodePixelPerMM) reEncodePixelPerMM = langext.Coalesce(opt.reEncodePixelPerMM, reEncodePixelPerMM)
crop = langext.CoalesceOpt(opt.crop, crop) crop = langext.CoalesceOpt(opt.crop, crop)
} }
regName := img.Name regName := img.Name
if imageFit != nil || fillColor != nil || crop != nil { if imageFit != nil || fillColor != nil || crop != nil || compression != nil {
var dataimg image.Image var dataimg image.Image
if img.Image != nil { if img.Image != nil {
@ -261,6 +263,16 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) {
b.b.SetError(err) b.b.SetError(err)
return 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 { 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 { if err != nil {
b.b.SetError(err) b.b.SetError(err)
return return
@ -301,6 +313,8 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) {
imageType = "GIF" imageType = "GIF"
} }
_ = os.WriteFile("/tmp/c.png", bfr.Bytes(), 0755)
b.b.RegisterImageOptionsReader(regName, gofpdf.ImageOptions{ImageType: imageType}, &bfr) b.b.RegisterImageOptionsReader(regName, gofpdf.ImageOptions{ImageType: imageType}, &bfr)
} }