|
@@ -17,7 +17,8 @@ export async function addWatermark(
|
|
|
index: number,
|
|
|
trackMode: string,
|
|
|
x = 0.01,
|
|
|
- y = 0.03
|
|
|
+ y = 0.03,
|
|
|
+ colorMap: any = {}
|
|
|
): Promise<boolean> {
|
|
|
const file = path.join(...filePath);
|
|
|
if (
|
|
@@ -50,8 +51,6 @@ export async function addWatermark(
|
|
|
}
|
|
|
const fontFile = store.config.watermark.fontFile;
|
|
|
const color = store.config.watermark.color;
|
|
|
- const nextColor = store.config.watermark.nextColor;
|
|
|
- const otherColor = store.config.watermark.otherColor;
|
|
|
const image = Buffer.from(imageData);
|
|
|
// const size = sizeOf(image);
|
|
|
// console.log(size);
|
|
@@ -243,35 +242,13 @@ export async function addWatermark(
|
|
|
// imgData.font(fontFile, fontSize).fill(color);
|
|
|
const tags = student.tags[index];
|
|
|
|
|
|
- let userIds: any = tags.map((item: any) => item.userId || 0);
|
|
|
- userIds = Array.from(new Set(userIds));
|
|
|
- userIds.sort();
|
|
|
- const colorMap: any = {
|
|
|
- "0": color,
|
|
|
- };
|
|
|
- let startIndex = 1;
|
|
|
- if (!userIds.includes(0)) {
|
|
|
- startIndex = 0;
|
|
|
- }
|
|
|
-
|
|
|
- for (let i = 0; i < userIds.length; i++) {
|
|
|
- const uId: string | number = userIds[i];
|
|
|
- if (i == startIndex) {
|
|
|
- colorMap[uId + ""] = color;
|
|
|
- } else if (i == startIndex + 1) {
|
|
|
- colorMap[uId + ""] = nextColor;
|
|
|
- } else if (i > startIndex + 1) {
|
|
|
- colorMap[uId + ""] = otherColor;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
for (let i = 0; i < tags.length; i++) {
|
|
|
const tag = tags[i];
|
|
|
if (tag.content != undefined) {
|
|
|
let top = tag.top;
|
|
|
imgData
|
|
|
.font(fontFile, fontSize)
|
|
|
- .fill(colorMap[tag.userId + ""] || color);
|
|
|
+ .fill(colorMap[tag.groupNumber + ""][tag.userId + ""] || "gray");
|
|
|
for (let j = 0; j < tag.content.length; j++) {
|
|
|
imgData.drawText(tag.left, top, tag.content[j]);
|
|
|
top += height;
|
|
@@ -300,7 +277,7 @@ export async function saveImage(
|
|
|
filePath: string[]
|
|
|
): Promise<boolean> {
|
|
|
const file = path.join(...filePath);
|
|
|
- console.log("saveImage file:", file);
|
|
|
+ // console.log("saveImage file:", file);
|
|
|
if (store.pageInputs["/image-download"].append && fs.existsSync(file)) {
|
|
|
console.log(file + " already exists");
|
|
|
return true;
|