index.js
701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import UTIF from 'utif';
const MIME_TYPE = 'image/tiff';
export default () => ({
mime: { [MIME_TYPE]: ['tiff', 'tif'] },
constants: {
MIME_TIFF: MIME_TYPE
},
decoders: {
[MIME_TYPE]: data => {
const ifds = UTIF.decode(data);
const page = ifds[0];
UTIF.decodeImages(data, ifds);
const rgba = UTIF.toRGBA8(page);
return {
data: Buffer.from(rgba),
width: page.t256[0],
height: page.t257[0]
};
}
},
encoders: {
[MIME_TYPE]: image => {
const tiff = UTIF.encodeImage(
image.bitmap.data,
image.bitmap.width,
image.bitmap.height
);
return Buffer.from(tiff);
}
}
});