From 9bb3bdb51b46f9ae90925aa66170e760a63b58c9 Mon Sep 17 00:00:00 2001 From: yeqown Date: Sat, 30 Mar 2024 11:23:09 +0800 Subject: [PATCH] fix(writer): transparent takes no effect on halftone image --- example/with-halftone/README.md | 26 +++++++++++++--- .../with-halftone/halftone-qr-transparent.png | Bin 0 -> 6874 bytes .../{halftone-qr.jpeg => halftone-qr.png} | Bin example/with-halftone/main.go | 24 +++++++++++++-- writer/standard/writer.go | 29 +++++++++++++++--- 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 example/with-halftone/halftone-qr-transparent.png rename example/with-halftone/{halftone-qr.jpeg => halftone-qr.png} (100%) diff --git a/example/with-halftone/README.md b/example/with-halftone/README.md index e11e4e9..a53be2b 100644 --- a/example/with-halftone/README.md +++ b/example/with-halftone/README.md @@ -4,16 +4,33 @@ > the gap between qr blocks could mislead the recognizer. ```go + +var ( + transparent = flag.Bool("transparent", false, "set background to transparent") +) + func main() { qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode") if err != nil { panic(err) } - - w0, err := standard.New("./repository_qrcode.png", + + options := []standard.ImageOption{ standard.WithHalftone("./test.jpeg"), standard.WithQRWidth(21), - ) + } + filename := "./halftone-qr.png" + + if *transparent { + options = append( + options, + standard.WithBuiltinImageEncoder(standard.PNG_FORMAT), + standard.WithBgTransparent(), + ) + filename = "./halftone-qr-transparent.png" + } + + w0, err := standard.New(filename, options...) handleErr(err) err = qrc.Save(w0) handleErr(err) @@ -26,4 +43,5 @@ func main() { #### output image - \ No newline at end of file + + diff --git a/example/with-halftone/halftone-qr-transparent.png b/example/with-halftone/halftone-qr-transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..1ef970c044d90ad77ba78d7817fed1ea7db1af7e GIT binary patch literal 6874 zcmdT}dsI_rwvRfF1uZ&5b8Vf1y&Vxle6+MwAR1d++oC1WCLss}1!O1>PyE&>mas9|Z*KVQw(jxWRTzt*y65ymFYcXFiJN+t90yRS5BW#o z$CD4PLZ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