更新金属机箱3.5寸小SKU:按最新标准重新生成,数据盘组合到各SKU;配件清单新增HDD-1T/3T/4T/6T

This commit is contained in:
12600k-rog-d4
2026-05-08 01:54:33 +08:00
parent 20fef11239
commit ab39e413fb
213 changed files with 1553 additions and 9691 deletions

View File

@@ -1,71 +1,81 @@
---
name: image-tools
description: 图片处理工具,用于检查图片信息、HTML转PNG、裁剪水印等操作。当用户需要处理产品图片、转换HTML为图片、或去除图片水印时使用此技能。
description: 阿里云万相2.7图生图工具,用于AI生成产品主图、场景图、电商素材。Invoke when user needs to generate product images, e-commerce visuals, or AI image editing.
---
# Image Tools
# Image Tools - 万相2.7 AI图生图
## Overview
使用阿里云百炼 **wan2.7-image-pro** 模型进行 AI 图生图处理,支持文生图、图生图、图片编辑。
提供产品图片处理相关功能包括检查图片元信息、HTML页面截图、裁剪水印等操作。适用于产品文档和图片批量处理场景。
## 前提条件
## Quick Start
环境变量 `DASHSCOPE_API_KEY` 已配置默认使用内置Key
使用前需安装依赖:
## 基本用法
```bash
cd tools/image-tools/scripts
npm install
python wan_image_edit.py <提示词> <输入图片> [输出路径] [尺寸]
```
## Tasks
**参数说明**
- `提示词`: 描述想要的效果,支持中英文
- `输入图片`: 产品图片路径PNG/JPG留空则为文生图
- `输出路径`: 输出文件名(可选,默认 wan_output.png
- `尺寸`: 1K 或 2K可选默认 2K
### 检查图片信息
查看图片的宽度、高度、格式等元信息:
## 示例
```bash
cd tools/image-tools/scripts
node check-image-info.js
# 白底产品图
python wan_image_edit.py "keep the product, pure white background, professional e-commerce photo" "product.png" "output.png"
# 场景图
python wan_image_edit.py "place product on modern desk, cozy home office" "product.png" "scene.png"
# 高性能风格
python wan_image_edit.py "cyberpunk gaming setup with RGB lights, benchmark scores" "product.png" "gaming.png" "2K"
# 文生图(无输入图片)
python wan_image_edit.py "futuristic NAS server in data center" "" "t2i.png"
# 直接在图上添加文字
python wan_image_edit.py "keep product, add bold text: 千兆高速传输, professional tech background" "product.png" "with_text.png"
```
**用途**:批量检查产品图片尺寸,确保符合规格要求。
## 可用尺寸
### HTML 转 PNG
| 尺寸 | 分辨率 | 适用场景 |
|-----|-------|---------|
| 1K | 1024x1024 | 快速预览、轮播图 |
| 2K | 2048x2048 | 主图、海报(推荐)|
将HTML文件转换为PNG图片截图
## 代码调用
```bash
cd tools/image-tools/scripts
node convert-html-to-png.js
```python
from wan_image_edit import wan_image_edit
# 基础调用
wan_image_edit(
prompt="keep the product, white background",
image_path="product.png",
output_path="output.png",
size="2K"
)
# 批量生成多张
styles = [
("white bg", "product.png", "white.png"),
("cyberpunk", "product.png", "cyber.png"),
("data center", "product.png", "datacenter.png"),
]
for prompt, img, out in styles:
wan_image_edit(prompt, img, out)
```
**用途**将产品配置清单HTML转换为PNG图片用于产品展示。
## 提示词技巧
### 裁剪水印
裁剪图片底部水印区域默认裁剪底部300px
```bash
cd tools/image-tools/scripts
node remove-watermark.js
```
**用途**:批量处理产品图片,去除底部水印。
## Configuration
脚本默认处理路径为 `产品/飞牛 NAS/fyd-亚克力机箱 - 单/详情` 目录。如需修改:
- **check-image-info.js**: 修改 `imageDir` 变量
- **convert-html-to-png.js**: 修改 `detailDir` 变量及文件过滤条件
- **remove-watermark.js**: 修改 `imageDir``CROP_BOTTOM_HEIGHT` 常量
## Resources
### scripts/
- `check-image-info.js` - 图片信息检查脚本
- `convert-html-to-png.js` - HTML转PNG截图脚本
- `remove-watermark.js` - 水印裁剪脚本
- `package.json` - Node.js 依赖配置
- **保持产品**: "keep the product", "retain the original product"
- **背景**: "white background", "modern office", "data center"
- **风格**: "cyberpunk", "minimalist", "professional"
- **氛围**: "dramatic lighting", "warm tones", "neon lights"
- **添加文字**: "add bold text: 千兆高速传输"

View File

@@ -1,27 +0,0 @@
const sharp = require('sharp');
const path = require('path');
const fs = require('fs');
async function checkImageInfo() {
const imageDir = path.join(__dirname, '产品', '飞牛 NAS', 'fyd-亚克力机箱 - 单', '详情', 'image');
const imageFiles = fs.readdirSync(imageDir).filter(file => file.endsWith('.jpg'));
console.log('📸 图片信息检查\n');
for (const imageFile of imageFiles) {
const imagePath = path.join(imageDir, imageFile);
const metadata = await sharp(imagePath).metadata();
console.log(`${imageFile}:`);
console.log(` 宽度: ${metadata.width}px`);
console.log(` 高度: ${metadata.height}px`);
console.log(` 格式: ${metadata.format}`);
console.log('');
}
}
checkImageInfo().catch(error => {
console.error('💥 检查过程出错:', error);
process.exit(1);
});

View File

@@ -1,58 +0,0 @@
const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
async function convertHtmlToPng() {
console.log('🚀 启动 HTML 转 PNG 转换工具...\n');
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setViewport({ width: 1000, height: 1000 });
const detailDir = 'G:\\stonelan-workspace\\membank\\产品\\Linux主机\\详情';
const htmlFiles = fs.readdirSync(detailDir)
.filter(file => file.endsWith('.html'));
console.log(`📁 找到 ${htmlFiles.length} 个 HTML 文件需要转换\n`);
for (const htmlFile of htmlFiles) {
try {
const htmlPath = path.join(detailDir, htmlFile);
const pngFile = htmlFile.replace('.html', '.png');
const pngPath = path.join(detailDir, pngFile);
console.log(`📄 正在转换: ${htmlFile}`);
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
await page.goto(fileUrl, {
waitUntil: 'networkidle0',
timeout: 10000
});
await page.screenshot({
path: pngPath,
fullPage: true,
type: 'png'
});
console.log(`✅ 已生成: ${pngFile}\n`);
} catch (error) {
console.error(`❌ 转换失败 ${htmlFile}: ${error.message}\n`);
}
}
await browser.close();
console.log('✨ 所有转换任务已完成!');
}
convertHtmlToPng().catch(error => {
console.error('💥 转换过程出错:', error);
process.exit(1);
});

View File

@@ -1,60 +0,0 @@
const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
async function convertHtmlToPng() {
console.log('🚀 启动主图 HTML 转 PNG 转换工具...\n');
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
// 主图尺寸 800x800
await page.setViewport({ width: 1000, height: 1000 });
const mainImageDir = 'G:\\stonelan-workspace\\membank\\产品\\飞牛 NAS\\fyd-亚克力机箱 - 单\\主图';
const htmlFiles = fs.readdirSync(mainImageDir)
.filter(file => file.endsWith('.html') && file.includes('主图'));
console.log(`📁 找到 ${htmlFiles.length} 个主图 HTML 文件需要转换\n`);
for (const htmlFile of htmlFiles) {
try {
const htmlPath = path.join(mainImageDir, htmlFile);
const pngFile = htmlFile.replace('.html', '.png');
const pngPath = path.join(mainImageDir, pngFile);
console.log(`📄 正在转换: ${htmlFile}`);
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
await page.goto(fileUrl, {
waitUntil: 'networkidle0',
timeout: 10000
});
await page.screenshot({
path: pngPath,
fullPage: false,
type: 'png',
clip: { x: 0, y: 0, width: 1000, height: 1000 }
});
console.log(`✅ 已生成: ${pngFile}\n`);
} catch (error) {
console.error(`❌ 转换失败 ${htmlFile}: ${error.message}\n`);
}
}
await browser.close();
console.log('✨ 所有主图转换任务已完成!');
}
convertHtmlToPng().catch(error => {
console.error('💥 转换过程出错:', error);
process.exit(1);
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +0,0 @@
{
"name": "membank",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@gitee.com:xiongmaojames/membank.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"puppeteer": "^24.40.0",
"sharp": "^0.34.5"
}
}

View File

@@ -1,64 +0,0 @@
# -*- coding: utf-8 -*-
"""
产品图片抠图工具
使用rembg库自动去除图片背景
"""
import os
import sys
try:
from rembg import remove
from PIL import Image
except ImportError:
print("Missing dependencies, installing...")
os.system("pip install rembg pillow")
from rembg import remove
from PIL import Image
def remove_background(input_path, output_path):
"""
去除图片背景
"""
try:
print(f"Processing: {input_path}")
# 打开原始图片
with open(input_path, 'rb') as input_file:
input_data = input_file.read()
# 去除背景
output_data = remove(input_data)
# 保存结果
with open(output_path, 'wb') as output_file:
output_file.write(output_data)
print(f"Saved: {output_path}")
return True
except Exception as e:
print(f"Error: {e}")
return False
if __name__ == "__main__":
# 产品图片路径
image_dir = r"g:\stonelan-workspace\membank\产品\飞牛 NAS\fyd-亚克力机箱 - 单\image"
# 要处理的图片
input_image = os.path.join(image_dir, "正面.jpg")
output_image = os.path.join(image_dir, "正面_抠图.png")
# 检查文件是否存在
if not os.path.exists(input_image):
print(f"File not found: {input_image}")
sys.exit(1)
# 执行抠图
success = remove_background(input_image, output_image)
if success:
print(f"\nBackground removal completed!")
print(f"Original: {input_image}")
print(f"Result: {output_image}")
else:
print("\nBackground removal failed!")
sys.exit(1)

View File

@@ -1,51 +0,0 @@
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);
});

View File

@@ -1,58 +0,0 @@
const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
async function convertMainImageToPng() {
console.log('🎨 启动主图渲染工具...\n');
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setViewport({ width: 800, height: 800 });
const mainImageDir = 'G:\\stonelan-workspace\\membank\\产品\\飞牛 NAS\\fyd-亚克力机箱 - 单\\主图';
const htmlFiles = fs.readdirSync(mainImageDir)
.filter(file => file.endsWith('.html'));
console.log(`📁 找到 ${htmlFiles.length} 个主图HTML文件需要渲染\n`);
for (const htmlFile of htmlFiles) {
try {
const htmlPath = path.join(mainImageDir, htmlFile);
const pngFile = htmlFile.replace('.html', '.png');
const pngPath = path.join(mainImageDir, pngFile);
console.log(`📄 正在渲染: ${htmlFile}`);
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
await page.goto(fileUrl, {
waitUntil: 'networkidle0',
timeout: 10000
});
await page.screenshot({
path: pngPath,
fullPage: true,
type: 'png'
});
console.log(`✅ 已生成: ${pngFile}\n`);
} catch (error) {
console.error(`❌ 渲染失败 ${htmlFile}: ${error.message}\n`);
}
}
await browser.close();
console.log('✨ 所有主图渲染完成!');
}
convertMainImageToPng().catch(error => {
console.error('💥 渲染过程出错:', error);
process.exit(1);
});

View File

@@ -0,0 +1,123 @@
import os
import sys
import base64
import mimetypes
import requests
from urllib.request import urlretrieve
API_KEY = os.getenv("DASHSCOPE_API_KEY", "")
DEFAULT_API_KEY = "sk-ef591b52e48840c6a63899c8901a9428"
if not API_KEY:
API_KEY = DEFAULT_API_KEY
print(f"使用默认API Key (前8位): {DEFAULT_API_KEY[:8]}...")
def encode_image(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type:
mime_type = "image/png"
with open(file_path, "rb") as f:
return f"data:{mime_type};base64,{base64.b64encode(f.read()).decode('utf-8')}"
def wan_image_edit(
prompt,
image_path,
output_path="wan_output.png",
size="2K",
negative_prompt="",
n=1,
prompt_extend=True
):
"""
万相2.7图生图 - 基于输入图片和提示词生成新图
参数:
prompt: 提示词,描述想要的效果
image_path: 输入图片路径
output_path: 输出图片路径
size: 输出尺寸 ("2K""1K")
negative_prompt: 反向提示词
n: 生成数量 (1-4)
prompt_extend: 是否启用提示词扩展
示例:
python wan_image_edit.py "keep the product, white background" "product.png" "output.png"
"""
print(f"提示词: {prompt}")
print(f"输入图片: {image_path}")
print(f"输出路径: {output_path}")
print(f"尺寸: {size}")
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
}
content = [{"text": prompt}]
if image_path:
content.append({"image": encode_image(image_path)})
payload = {
"model": "wan2.7-image-pro",
"input": {
"messages": [{
"role": "user",
"content": content
}]
},
"parameters": {
"size": size,
"n": n,
"prompt_extend": prompt_extend,
"watermark": False
}
}
if negative_prompt:
payload["parameters"]["negative_prompt"] = negative_prompt
try:
resp = requests.post(url, headers=headers, json=payload, timeout=120)
result = resp.json()
if resp.status_code == 200 and "output" in result:
choices = result["output"].get("choices", [])
if choices:
for idx, choice in enumerate(choices):
content_list = choice.get("message", {}).get("content", [])
for item in content_list:
if item.get("type") == "image":
image_url = item["image"]
out_path = output_path if n == 1 else output_path.replace(".png", f"_{idx}.png").replace(".jpg", f"_{idx}.jpg")
urlretrieve(image_url, out_path)
print(f"成功: {out_path}")
return True
else:
msg = result.get("message", str(result))
print(f"失败: {msg}")
return False
except requests.exceptions.Timeout:
print("请求超时,请重试")
return False
except Exception as e:
print(f"错误: {e}")
return False
if __name__ == "__main__":
if len(sys.argv) < 3:
print("用法: python wan_image_edit.py <提示词> <输入图片> [输出路径] [尺寸]")
print("")
print("示例:")
print(' python wan_image_edit.py "keep the product, white background" "product.png" "output.png"')
print(' python wan_image_edit.py "cyberpunk style" "product.png" "output.png" "2K"')
print("")
print("尺寸选项: 1K (1024x1024), 2K (2048x2048)")
sys.exit(1)
prompt = sys.argv[1]
image_path = sys.argv[2]
output_path = sys.argv[3] if len(sys.argv) > 3 else "wan_output.png"
size = sys.argv[4] if len(sys.argv) > 4 else "2K"
wan_image_edit(prompt, image_path, output_path, size)