From 3f149cc825504eb03505e2a3525e9990953ca059 Mon Sep 17 00:00:00 2001 From: Mohammad Wasif Date: Fri, 1 Aug 2025 13:51:53 +0400 Subject: [PATCH 1/4] fixed png images rendering issues for qrcode --- lib/image/png.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/image/png.js b/lib/image/png.js index 504ce8a8..ae244008 100644 --- a/lib/image/png.js +++ b/lib/image/png.js @@ -103,7 +103,7 @@ class PNGImage { Subtype: 'Image', Height: this.height, Width: this.width, - BitsPerComponent: 8, + BitsPerComponent: this.image.hasAlphaChannel ? 8 : this.image.bits, Filter: 'FlateDecode', ColorSpace: 'DeviceGray', Decode: [0, 1], From 857820e5bd61d586acdc1aaa2fc0e0ddfdedd1b9 Mon Sep 17 00:00:00 2001 From: Mohammad Wasif Date: Fri, 1 Aug 2025 15:54:32 +0400 Subject: [PATCH 2/4] updated changelog.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c64641..5585336c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Unreleased +### [v0.17.2] - 2025-08-01 + +- fixed png images rendering issues for qrcode + + ### [v0.17.1] - 2025-05-02 - Fix null values in table cells rendering as `[object Object]` From 3f4916c22de9eb06de2eec267a0b5d35d3d71068 Mon Sep 17 00:00:00 2001 From: Mohammad Wasif Date: Fri, 1 Aug 2025 17:11:39 +0400 Subject: [PATCH 3/4] some lines were missing so This is the final submission --- lib/image/png.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/image/png.js b/lib/image/png.js index ae244008..c5230433 100644 --- a/lib/image/png.js +++ b/lib/image/png.js @@ -97,13 +97,13 @@ class PNGImage { } finalize() { - if (this.alphaChannel) { + if (this.image.hasAlphaChannel) { const sMask = this.document.ref({ Type: 'XObject', Subtype: 'Image', Height: this.height, Width: this.width, - BitsPerComponent: this.image.hasAlphaChannel ? 8 : this.image.bits, + BitsPerComponent: 8, Filter: 'FlateDecode', ColorSpace: 'DeviceGray', Decode: [0, 1], From 4275a3b17c8dc26530b9a82fc41ca9dacc425a9d Mon Sep 17 00:00:00 2001 From: Mohammad Wasif Date: Tue, 9 Sep 2025 13:02:07 +0400 Subject: [PATCH 4/4] removed the smask for one test case removed the smask for one test case and test the output of that particular image is perfect --- lib/image/png.js | 2 +- tests/unit/png.spec.js | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/image/png.js b/lib/image/png.js index c5230433..13407369 100644 --- a/lib/image/png.js +++ b/lib/image/png.js @@ -97,7 +97,7 @@ class PNGImage { } finalize() { - if (this.image.hasAlphaChannel) { + if (this.image.hasAlphaChannel && this.alphaChannel) { const sMask = this.document.ref({ Type: 'XObject', Subtype: 'Image', diff --git a/tests/unit/png.spec.js b/tests/unit/png.spec.js index 9c6cd521..2dc20ac0 100644 --- a/tests/unit/png.spec.js +++ b/tests/unit/png.spec.js @@ -237,7 +237,6 @@ describe('PNGImage', () => { Type: 'XObject', Width: 32, DecodeParms: expect.any(PDFReference), - SMask: expect.any(PDFReference), }); expect(img.obj.data.DecodeParms.data).toMatchObject({ @@ -246,18 +245,6 @@ describe('PNGImage', () => { Columns: 32, Predictor: 15, }); - - expect(img.obj.data.SMask.data).toMatchObject({ - BitsPerComponent: 8, - ColorSpace: 'DeviceGray', - Decode: [0, 1], - Filter: 'FlateDecode', - Height: 32, - Length: 16, - Subtype: 'Image', - Type: 'XObject', - Width: 32, - }); }); test('Grayscale', () => {