Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/custom/src/index.js
1129 views
1
import Jimp, {
2
addType,
3
addJimpMethods,
4
addConstants,
5
jimpEvChange
6
} from '@jimp/core';
7
8
export default function configure(configuration, jimpInstance = Jimp) {
9
const jimpConfig = {
10
hasAlpha: {},
11
encoders: {},
12
decoders: {},
13
class: {},
14
constants: {}
15
};
16
17
function addToConfig(newConfig) {
18
Object.entries(newConfig).forEach(([key, value]) => {
19
jimpConfig[key] = {
20
...jimpConfig[key],
21
...value
22
};
23
});
24
}
25
26
function addImageType(typeModule) {
27
const type = typeModule();
28
29
if (Array.isArray(type.mime)) {
30
addType(...type.mime);
31
} else {
32
Object.entries(type.mime).forEach(mimeType => addType(...mimeType));
33
}
34
35
delete type.mime;
36
addToConfig(type);
37
}
38
39
function addPlugin(pluginModule) {
40
const plugin = pluginModule(jimpEvChange) || {};
41
if (!plugin.class && !plugin.constants) {
42
// Default to class function
43
addToConfig({ class: plugin });
44
} else {
45
addToConfig(plugin);
46
}
47
}
48
49
if (configuration.types) {
50
configuration.types.forEach(addImageType);
51
52
jimpInstance.decoders = {
53
...jimpInstance.decoders,
54
...jimpConfig.decoders
55
};
56
jimpInstance.encoders = {
57
...jimpInstance.encoders,
58
...jimpConfig.encoders
59
};
60
jimpInstance.hasAlpha = {
61
...jimpInstance.hasAlpha,
62
...jimpConfig.hasAlpha
63
};
64
}
65
66
if (configuration.plugins) {
67
configuration.plugins.forEach(addPlugin);
68
}
69
70
addJimpMethods(jimpConfig.class, jimpInstance);
71
addConstants(jimpConfig.constants, jimpInstance);
72
73
return Jimp;
74
}
75
76