支持常见图像格式相互转换或保留原格式压缩的自动化工具,使用前请确保已安装 Pillow 库:
bash
pip install Pillow
# 或使用uv
uv add Pillow
--to-format 标志(最高优先级)--compress 模式:保留输入格式Convert PNG to JPEG:
bash
python scripts/convert.py input.png output.jpg
Convert WebP to PNG:
bash
python scripts/convert.py input.webp output.png
Convert all images in a directory to PNG:
bash
python scripts/convert.py ./input_dir ./output_dir --to-format png
Convert JPEG to WebP even if output has .jpg extension:
bash
python scripts/convert.py input.jpg output.jpg --to-format webp
Compress PNG with quality 75 (preserves format):
bash
python scripts/convert.py input.png output.png --compress --compress-quality 75
Process multiple files using comma-separated list, glob patterns, or wildcard:
bash
# Comma-separated files
python scripts/convert.py "img1.png,img2.jpg,img3.webp" output_dir/ --to-format png
# Glob pattern
python scripts/convert.py "*.jpg" output_dir/ --to-format webp
# Multiple patterns
python scripts/convert.py "*.png,*.jpg" output_dir/ --to-format webp
# Parallel processing (4 threads)
python scripts/convert.py "*.jpg" output_dir/ --threads 4
# Verbose output
python scripts/convert.py "*.jpg" output_dir/ -v
Convert JPEG to WebP with quality 85:
bash
python scripts/convert.py input.jpg output.webp --quality 85
Convert directory to WebP (keeps original files):
bash
python scripts/convert.py ./images/ ./webp_output/
Lossless compression:
bash
python scripts/convert.py input.png output.webp --lossless
Scale image (longest edge 1920px):
bash
python scripts/convert.py input.jpg output.webp --max-size 1920
Batch compress directory (preserves format):
bash
python scripts/convert.py ./images/ ./compressed/ --compress
功能说明相互转换支持常见图像格式之间的相互转换批量转换支持目录、文件列表、逗号分隔、通配符输入并行处理多线程批量转换加速质量控制有损压缩质量 1-100无损模式保持原始像素质量尺寸缩放按最长边等比缩放色彩空间自动转换 CMYK→RGB,调色板→RGBA元数据清除 EXIF,保留 ICC 配置文件格式保留压缩保留原格式进行压缩(PNG/JPEG/GIF/WebP/TIFF)
参数说明默认值--to-format明确指定目标格式 (jpeg, png, webp, gif, bmp, tiff),优先级高于输出扩展名无--quality压缩质量 (1-100)90--max-size最长边缩放像素不缩放--lossless启用无损压缩False
参数说明默认值--compress启用压缩模式,保留原格式False--compress-quality压缩质量 (1-100)85--compress-levelPNG/TIFF 压缩级别 (0-9)6
参数说明默认值--threads并行处理线程数1--verbose, -v显示详细进度信息False
详细 WebP 参数配置请查看 webp_settings.md。