Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

Binary file not shown.
+23
View File
@@ -0,0 +1,23 @@
import sharp from "sharp";
import fs from "fs";
import path from "path";
// Input and output file paths
const inputPath = "./imageFolder";
const outputPath = "./compressedImage";
export async function compressImages() {
const images = fs.readdirSync(inputPath);
await Promise.all(
images.map((image) => {
const inputImagePath = path.join(inputPath, image);
const outputImagePath = path.join(outputPath, image);
// Compress the image (adjust quality for JPEG)
return sharp(inputImagePath)
.resize({ width: 700 }) // optional resize
.jpeg({ quality: 70 }) // lower quality = higher compression
//.rotate(90) // rotate by 90 degrees clockwise
.toFile(outputImagePath);
}),
);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

+6
View File
@@ -0,0 +1,6 @@
{
"orderNumber": "876894974",
"description": "bla",
"location": "new york",
"damagedColumnNo": ""
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.
+123
View File
@@ -0,0 +1,123 @@
import { TemplateHandler } from "easy-template-x";
import fs from "fs";
const templateHandler = new TemplateHandler();
const templateFile = fs.readFileSync("Photo for Column with Single lamp.docx");
const configData = JSON.parse(fs.readFileSync("config.json", "utf-8"));
const data = {
orderNumber: configData.orderNumber,
description: configData.description,
location: configData.location,
damagedColumnNo: configData.damagedColumnNo,
image1: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img1.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image2: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img2.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image3: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img3.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image4: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img4.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image5: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img5.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image6: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img6.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image7: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img7.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image8: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img8.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image9: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img9.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image10: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img10.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image11: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img11.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image12: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img12.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image13: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img13.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image14: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img14.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
image15: {
_type: "image",
source: fs.readFileSync(`./watermarkedImages/img15.JPG`),
format: "image/jpeg",
width: 246,
height: 186,
},
};
const doc = await templateHandler.process(templateFile, data);
fs.writeFileSync("report.docx", doc);
+65
View File
@@ -0,0 +1,65 @@
import sharp from "sharp";
import { exiftool } from "exiftool-vendored";
import fs from "fs";
import path from "path";
import { compressImages } from "./compress-backup.js";
// Folder paths
const inputFolder = "./compressedImage";
const outputFolder = "./watermarkedImages";
fs.mkdirSync(outputFolder, { recursive: true });
// Add watermark to all images
const addWatermark = async (inputPath, outputPath, watermarkText) => {
const { width, height } = await sharp(inputPath).metadata();
// Generate overlay text as an image
const svg = `
<svg width="${width}" height="${height}">
<style>
.label {
fill: red;
font-size: 30px;
font-family: Arial, sans-serif;
}
</style>
<text x="${width - 10}" y="${height - 10}" text-anchor="end" class="label">${watermarkText}</text>
</svg>
`;
return sharp(inputPath)
.composite([{ input: Buffer.from(svg), top: 0, left: 0 }])
.toFile(outputPath);
};
async function getImageDate(filePath) {
try {
const tags = await exiftool.read(filePath);
console.log("DateTimeOriginal: ", tags.FileModifyDate.rawValue); // Example: 2024-05-21T14:32:18.000Z
const dateOnly = tags.FileModifyDate.rawValue.split(" ")[0];
const timeOnly = tags.FileModifyDate.rawValue.split(" ")[1].slice(0, 5);
const [year, month, day] = dateOnly.split(":");
const formatted = `${year}-${month}-${day} ${timeOnly}`;
return formatted;
} catch (err) {
console.error("Failed to read EXIF:", err);
}
}
async function main() {
await compressImages();
// Process all images
const files = fs
.readdirSync(inputFolder)
.filter((f) => /\.(jpe?g|png)$/i.test(f));
for (const file of files) {
const inputPath = path.join(inputFolder, file);
const outputPath = path.join(outputFolder, file);
const watermarkText = await getImageDate(inputPath);
await addWatermark(inputPath, outputPath, watermarkText);
console.log(`Watermarked: ${file}`);
}
await exiftool.end(); // Important to close the process
}
main();
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB