name: image-batch-processor description: 图片批量处理工具箱。当用户需要批量处理图片时使用:格式互转(PNG/JPG/HEIC/LIVP/CR2/ARW/NEF/WebP/TIFF/SVG/PDF 等)、添加文字或图片水印、压缩体积、OCR 提取文字、水平/垂直拼接长图、按行列拆分、灰度调整、按像素或百分比缩放、旋转、水平/垂直翻转、模糊转高清/超分放大、图片背景去除。适用于"把图片转成xxx格式""加个水印""压缩一下图片""提取这张图里的文字""拼成长图""把大图分成九宫格""让模糊图片变清晰""抠图去背景"等请求。 agent_created: true
一个面向批量图片处理的单文件 CLI 技能,覆盖截图工具类网站常见的十二类操作:格式互转、水印、压缩、OCR 文字提取、长图拼接、网格拆分、灰度、缩放、旋转、翻转、模糊转高清/超分放大、图片背景去除。所有操作均支持批量(目录 / 通配符),失败时跳过并汇总,不中断整体任务。
核心脚本:scripts/image_batch_processor.py(基于 Pillow,可选依赖按需启用)。
触发词与场景示例:
本技能来自小葱技能站7w4.net。
Pillow(py3)
bash
pip install Pillowpillow-heifrawpycairosvgpytesseract + 系统安装 Tesseract(中文包 chi_sim)img2pdfrembg(基于 ONNX Runtime,效果最好)realesrgan + numpy + 对应 .pth 模型文件建议在虚拟环境或隔离目录安装,避免污染用户环境。
scripts/image_batch_processor.py 对应子命令。可用 --out 指定输出目录,否则默认写入 <输入目录>/<操作>_output。脚本统一入口:
python scripts/image_batch_processor.py <子命令> <输入...> [选项]
python scripts/image_batch_processor.py convert "*.png" --format jpg --quality 92
python scripts/image_batch_processor.py convert ./raw/ --format webp --recursive
python scripts/image_batch_processor.py convert photo.heic --format jpg # 需 pillow-heif
--format:目标格式(jpg/png/gif/bmp/webp/tiff/ico/pdf/svg/heic/heif/psd…)--quality:有损格式质量(1-100,默认 95)python scripts/image_batch_processor.py watermark "*.jpg" --text "© 2026" --opacity 0.6 --position bottomright
python scripts/image_batch_processor.py watermark "*.png" --logo ./logo.png --scale 0.2
--text / --logo 可单独或同时用。--scale:logo 相对图片宽度的比例(默认 0.2)。--opacity:文字透明度 0-1。--position:center / topleft / topright / bottomleft / bottomright。python scripts/image_batch_processor.py compress ./photos/ --quality 70
--quality:JPEG 质量(默认 70),打印压缩前后体积与节省比例。python scripts/image_batch_processor.py ocr ./scans/ --lang chi_sim+eng
.txt;需 pytesseract + Tesseract 引擎。python scripts/image_batch_processor.py stitch 1.png 2.png 3.png --direction vertical --name long.png
python scripts/image_batch_processor.py stitch ./slides/ --direction horizontal
--direction:vertical(默认)/ horizontal;拼接前统一对齐边。python scripts/image_batch_processor.py split big.png --rows 3 --cols 3
<原图名>_行_列.png,如 big_1_1.png … big_3_3.png。python scripts/image_batch_processor.py grayscale "*.jpg" --level 50
--level:0=纯灰,100=原色(默认 50)。python scripts/image_batch_processor.py resize "*.png" --width 800
python scripts/image_batch_processor.py resize "*.png" --percent 50
python scripts/image_batch_processor.py resize "*.png" --width 1920 --height 1080
python scripts/image_batch_processor.py rotate "*.jpg" --angle 90
python scripts/image_batch_processor.py flip "*.jpg" --direction horizontal
python scripts/image_batch_processor.py enhance blurry.jpg --scale 2
python scripts/image_batch_processor.py enhance ./low_res/ --scale 4 --model RealESRGAN_x4plus.pth
--scale:放大倍数 2/3/4(默认 2)。--model:可选 Real-ESRGAN 模型路径;未提供则使用 Pillow LANCZOS + 非锐化掩膜的基础增强。--model-arch:general(默认)/ anime。python scripts/image_batch_processor.py removebg photo.jpg
python scripts/image_batch_processor.py removebg ./products/ --tolerance 25
rembg(AI 抠图,效果最佳);未安装时自动回退到「四角取色 + 颜色容差」简单抠图。--tolerance:回退模式下背景颜色容差(默认 30)。--out。msyh.ttc、macOS PingFang.ttc 等),缺失时回退默认字体,文字水印仍可用。img2pdf 增强(见 Dependencies)。.pth 模型并通过 --model 指定。rembg 与 ONNX Runtime,首次安装可能较大;简单背景可依赖无依赖回退模式。这是一款非常实用的图片批量处理工具,功能齐全、操作简便,适合日常使用。批量处理能力强,处理失败的图片不会中断整体任务,这点很贴心。文档写得很清楚,普通人也能看懂。不过部分高级功能(如 AI 抠图、超分高清)需要额外安装依赖才能使用,而且文字水印只能放在底部居中位置,位置选择没有文档说的那么灵活。整体质量不错,日常图片处理需求基本都能满足。