Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit ffdda49

Browse files
committed
Fix grayscale PNG images with alpha channel
1 parent 7c6134a commit ffdda49

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/image/png.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,18 @@ class PNGImage {
109109
splitAlphaChannel() {
110110
return this.image.decodePixels(pixels => {
111111
let a, p;
112-
const colorByteSize = (this.image.colors * this.image.bits) / 8;
112+
const colorCount = this.image.colors;
113+
const colorByteSize = (colorCount * this.image.bits) / 8;
113114
const pixelCount = this.width * this.height;
114115
const imgData = new Buffer(pixelCount * colorByteSize);
115116
const alphaChannel = new Buffer(pixelCount);
116117

117118
let i = p = a = 0;
118119
const len = pixels.length;
119120
while (i < len) {
120-
imgData[p++] = pixels[i++];
121-
imgData[p++] = pixels[i++];
122-
imgData[p++] = pixels[i++];
121+
pixels.copy(imgData, p, i, i + colorCount);
122+
p += colorCount;
123+
i += colorCount;
123124
alphaChannel[a++] = pixels[i++];
124125
}
125126

0 commit comments

Comments
 (0)