36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { spawn } from "child_process";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
|
|
/**
|
|
* Executes the Python watermark processor on an image file on disk.
|
|
* Applies:
|
|
* 1. School logo without background in top-left corner
|
|
* 2. Scannable official WeChat QR code in bottom-right corner
|
|
* 3. Bottom text: '上海健志空手道馆 · Shanghai Karate Club · Est. 2008'
|
|
*/
|
|
export async function applyWatermarkToFile(filePath: string): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
if (!fs.existsSync(filePath)) {
|
|
return resolve();
|
|
}
|
|
|
|
const scriptPath = path.join(process.cwd(), "watermark_processor.py");
|
|
const py = spawn("python", [scriptPath, filePath, filePath]);
|
|
|
|
py.on("close", (code) => {
|
|
if (code === 0) {
|
|
resolve();
|
|
} else {
|
|
console.warn(`[Watermark] Python watermark process exited with code ${code}`);
|
|
resolve(); // Graceful fallback
|
|
}
|
|
});
|
|
|
|
py.on("error", (err) => {
|
|
console.warn("[Watermark] Failed to spawn watermark process:", err);
|
|
resolve(); // Graceful fallback
|
|
});
|
|
});
|
|
}
|