image-js
Version:
Image processing and manipulation in JavaScript
25 lines • 887 B
JavaScript
import { P, match } from 'ts-pattern';
import { encodeBmp } from './encodeBmp.js';
import { encodeJpeg } from './encodeJpeg.js';
import { encodePng } from './encodePng.js';
export const ImageFormat = {
PNG: 'png',
JPG: 'jpg',
JPEG: 'jpeg',
BMP: 'bmp',
};
export const defaultPng = { format: 'png' };
/**
* Encodes the image to the specified format
* @param image - Image to encode.
* @param options - Format and options passed to the encoder.
* @returns The encoded image.
*/
export function encode(image, options = defaultPng) {
return match(options)
.with({ format: 'png' }, (options) => encodePng(image, options.encoderOptions))
.with({ format: P.union('jpg', 'jpeg') }, (options) => encodeJpeg(image, options.encoderOptions))
.with({ format: 'bmp' }, () => encodeBmp(image))
.exhaustive();
}
//# sourceMappingURL=encode.js.map