UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

21 lines 841 B
import imageType from 'image-type'; import { match } from 'ts-pattern'; import { decodeStackFromApng } from "./decodeApng.js"; import { decodeStackFromTiff } from './decodeTiff.js'; /** * Decode input data and create stack. Data format is automatically detected. * Possible formats: tiff. * @param data - Data to decode. * @returns The decoded image. */ export function decodeStack(data) { const typedArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); const type = imageType(typedArray); return match(type) .with({ mime: 'image/tiff' }, () => decodeStackFromTiff(typedArray)) .with({ mime: 'image/png' }, () => decodeStackFromApng(typedArray)) .otherwise(() => { throw new RangeError(`invalid data format: ${type?.mime}`); }); } //# sourceMappingURL=decodeStack.js.map