image-js
Version:
Image processing and manipulation in JavaScript
23 lines • 678 B
JavaScript
import { encode } from 'fast-png';
import { Mask } from '../Mask.js';
/**
* Creates a PNG buffer from an image.
* @param image - The image instance.
* @param options - PNG encoding options.
* @returns The buffer.
*/
export function encodePng(image, options) {
if ((image.colorModel !== 'RGB' &&
image.colorModel !== 'RGBA' &&
image.colorModel !== 'GREY' &&
image.colorModel !== 'GREYA') ||
image instanceof Mask) {
image = image.convertColor('GREY');
}
const { bitDepth: depth, ...other } = image.getRawImage();
return encode({
depth,
...other,
}, options);
}
//# sourceMappingURL=encodePng.js.map