feat: 为亚克力机箱-单生成5张主图及转换脚本

This commit is contained in:
12600k-rog-d4
2026-04-04 22:12:53 +08:00
parent 4277fa4ee5
commit cad20914cc
22 changed files with 3159 additions and 6 deletions

View File

@@ -0,0 +1,51 @@
const sharp = require('sharp');
const path = require('path');
const fs = require('fs');
const CROP_BOTTOM_HEIGHT = 300;
async function removeWatermark() {
console.log('🖼️ 开始裁剪图片水印...\n');
const imageDir = path.join(__dirname, '产品', '飞牛 NAS', 'fyd-亚克力机箱 - 单', '详情', 'image');
const backupDir = path.join(imageDir, 'backup');
const imageFiles = fs.readdirSync(backupDir).filter(file => file.endsWith('.jpg'));
console.log(`📸 找到 ${imageFiles.length} 张图片需要处理\n`);
console.log(`✂️ 裁剪设置: 从底部裁剪 ${CROP_BOTTOM_HEIGHT}px\n`);
for (const imageFile of imageFiles) {
try {
const backupPath = path.join(backupDir, imageFile);
const imagePath = path.join(imageDir, imageFile);
console.log(`📄 正在处理: ${imageFile}`);
const metadata = await sharp(backupPath).metadata();
const newHeight = metadata.height - CROP_BOTTOM_HEIGHT;
await sharp(backupPath)
.extract({
left: 0,
top: 0,
width: metadata.width,
height: newHeight
})
.toFile(imagePath);
console.log(` ✅ 已裁剪: ${metadata.width}x${metadata.height} -> ${metadata.width}x${newHeight}\n`);
} catch (error) {
console.error(` ❌ 处理失败 ${imageFile}: ${error.message}\n`);
}
}
console.log('✨ 所有图片处理完成!');
}
removeWatermark().catch(error => {
console.error('💥 处理过程出错:', error);
process.exit(1);
});