Skip to content

Commit e82c80c

Browse files
committed
fix: undo breaking change: alpha can be 0 or 1 again
1 parent 70be347 commit e82c80c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/PNGEncoder.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,22 @@ function checkInteger(value: number, name: string): number {
140140
function getColourType(
141141
data: IImageData
142142
): { channels: number; bitDepth: number; colourType: number } {
143-
const { channels = 4, alpha = true, bitDepth = 8 } = data;
143+
const { channels = 4, bitDepth = 8 } = data;
144144
if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {
145145
throw new RangeError(`unsupported number of channels: ${channels}`);
146146
}
147147
if (bitDepth !== 8 && bitDepth !== 16) {
148148
throw new RangeError(`unsupported bit depth: ${bitDepth}`);
149149
}
150+
151+
let { alpha = true } = data;
152+
if (alpha === 0 || alpha === 1) {
153+
alpha = Boolean(alpha);
154+
}
150155
if (typeof alpha !== 'boolean') {
151156
throw new TypeError(`unsupported alpha: ${alpha}`);
152157
}
158+
153159
const returnValue = { channels, bitDepth, colourType: -1 };
154160
switch (channels) {
155161
case 4:

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface IImageData {
3232
height: number;
3333
data: PNGDataArray;
3434
channels?: number;
35-
alpha?: boolean;
35+
alpha?: boolean | 0 | 1;
3636
bitDepth?: number;
3737
}
3838

0 commit comments

Comments
 (0)