-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
34 lines (31 loc) · 1.05 KB
/
index.js
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
const bindings = require('./build/Release/ag_images.node');
exports.PNG_NO_FILTERS = bindings.PNG_NO_FILTERS;
exports.PNG_FILTER_NONE = bindings.PNG_FILTER_NONE;
exports.PNG_FILTER_SUB = bindings.PNG_FILTER_SUB;
exports.PNG_FILTER_UP = bindings.PNG_FILTER_UP;
exports.PNG_FILTER_AVG = bindings.PNG_FILTER_AVG;
exports.PNG_FILTER_PAETH = bindings.PNG_FILTER_PAETH;
exports.PNG_ALL_FILTERS = bindings.PNG_ALL_FILTERS;
exports.encodePNG = function (width, height, data, options) {
return new Promise((resolve, reject) => {
bindings.encodePNG(width, height, data, options, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
})
});
};
exports.decodePNG = function (buffer, options) {
return new Promise((resolve, reject) => {
const premultiplied = options?.premultiplied || false;
bindings.decodePNG(buffer, premultiplied, (error, data, width, height) => {
if (error) {
reject(error);
} else {
resolve({ data, width, height, premultiplied });
}
})
});
};