-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
server.js
54 lines (46 loc) · 1.31 KB
/
server.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
/// <reference types="@citizenfx/server" />
/// <reference types="image-js" />
const imagejs = require('image-js');
const fs = require('fs');
const resName = GetCurrentResourceName();
const mainSavePath = `resources/${resName}/images`;
try {
if (!fs.existsSync(mainSavePath)) {
fs.mkdirSync(mainSavePath);
}
onNet('takeScreenshot', async (filename, type) => {
const savePath = `${mainSavePath}/${type}`;
if (!fs.existsSync(savePath)) {
fs.mkdirSync(savePath);
}
exports['screenshot-basic'].requestClientScreenshot(
source,
{
fileName: savePath + '/' + filename + '.png',
encoding: 'png',
quality: 1.0,
},
async (err, fileName) => {
let image = await imagejs.Image.load(fileName);
const coppedImage = image.crop({ x: image.width / 4.5, width: image.height });
image.data = coppedImage.data;
image.width = coppedImage.width;
image.height = coppedImage.height;
for (let x = 0; x < image.width; x++) {
for (let y = 0; y < image.height; y++) {
const pixelArr = image.getPixelXY(x, y);
const r = pixelArr[0];
const g = pixelArr[1];
const b = pixelArr[2];
if (g > r + b) {
image.setPixelXY(x, y, [255, 255, 255, 0]);
}
}
}
image.save(fileName);
}
);
});
} catch (error) {
console.error(error.message);
}