Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG grayscale alpha does not work #257

Open
pgundlach opened this issue Jun 8, 2023 · 1 comment
Open

PNG grayscale alpha does not work #257

pgundlach opened this issue Jun 8, 2023 · 1 comment

Comments

@pgundlach
Copy link

I can't include grayscale png images with alpha, they appear solid.

See this file:

package main

import (
	"github.com/signintech/gopdf"
)

func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
	pdf.AddPage()
	pdf.Image("gradient.png", 0, 0, nil)
	pdf.WritePdf("image.pdf")
}

and the following gradient.png:

gradient

The following diff solved it for me, but I don't know if this is correct or good.

diff --git a/image_obj_parse.go b/image_obj_parse.go
index 4304689..90375f5 100644
--- a/image_obj_parse.go
+++ b/image_obj_parse.go
@@ -427,17 +427,16 @@ func parsePng(f *bytes.Reader, info *imgInfo, imgConfig image.Config) error {
 
 				i++
 			}
-			info.smask, err = compress(alpha)
-			if err != nil {
-				return err
-			}
-
-			info.data, err = compress(color)
-			if err != nil {
-				return err
-			}
+		}
+		info.smask, err = compress(alpha)
+		if err != nil {
+			return err
 		}
 
+		info.data, err = compress(color)
+		if err != nil {
+			return err
+		}
 	} else {
 		info.data = data
 	}
@oneplus1000
Copy link
Collaborator

Yes, I think you got it right. I have solved as you suggested and pushed up already. thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants