-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.js
executable file
·65 lines (59 loc) · 1.94 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const lib = require('./lib.js');
const path = require('path');
const fs = require('fs');
class DigitalWatermarking{
static getConfig() {
return lib.getConfig()
}
static setConfig({opencvJsPath}) {
return lib.setConfig({opencvJsPath})
}
static getAbsoluteFilePath(filePath)
{
return path.isAbsolute(filePath)?filePath:path.join(process.cwd(),filePath);
}
static existsFilePath(filePath)
{
if(!fs.existsSync(filePath)){throw new Error(`not file in ${filePath}`);}
}
static isBuffer(fileBuf)
{
if((!(fileBuf instanceof Buffer))) {
throw new Error(`input not Buffer`);
}
}
static async transformImageWithText(srcFileName,watermarkText,fontSize,enCodeFileName)
{
const srcFilePath = DigitalWatermarking.getAbsoluteFilePath(srcFileName);
DigitalWatermarking.existsFilePath(srcFilePath);
return await lib.transformImageWithText(
srcFilePath,
watermarkText,fontSize,
DigitalWatermarking.getAbsoluteFilePath(enCodeFileName)
);
}
static async transformImageBufferWithText(srcBuffer,watermarkText,fontSize)
{
DigitalWatermarking.isBuffer(srcBuffer);
return await lib.transformImageWithText(
srcBuffer,
watermarkText,fontSize,
);
}
static async getTextFormImage(enCodeFileName,deCodeFileName)
{
const enCodeFilePath = DigitalWatermarking.getAbsoluteFilePath(enCodeFileName);
DigitalWatermarking.existsFilePath(enCodeFilePath);
return await lib.getTextFormImage(
enCodeFileName,
DigitalWatermarking.getAbsoluteFilePath(deCodeFileName)
);
}
static async getTextFormImageBuffer(enCodeBuffer) {
DigitalWatermarking.isBuffer(enCodeBuffer);
return await lib.getTextFormImage(
enCodeBuffer
);
}
}
module.exports = DigitalWatermarking;