image-enhancement-suite
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImage Enhancement Suite
图像增强套件
Professional image processing toolkit that handles common image tasks without requiring Photoshop or similar software. Process single images or entire folders with consistent, high-quality results.
专业图像处理工具包,无需Photoshop或类似软件即可处理常见图像任务。可处理单张图像或整个文件夹,输出结果一致且高质量。
Core Capabilities
核心功能
- Resize & Crop: Smart resizing with aspect ratio preservation, crop to specific dimensions
- Watermark: Add text or image watermarks with positioning and opacity control
- Color Correction: Brightness, contrast, saturation, sharpness adjustments
- Format Conversion: Convert between PNG, JPEG, WebP, BMP, TIFF, GIF
- Compression: Optimize file size with quality presets
- Filters: Apply preset filters (grayscale, sepia, vintage, blur, sharpen)
- Batch Processing: Process multiple images with same settings
- 调整尺寸与裁剪:智能调整尺寸并保留宽高比,可裁剪至特定尺寸
- 添加水印:添加文字或图片水印,支持位置与透明度控制
- 色彩校正:调整亮度、对比度、饱和度、锐度
- 格式转换:在PNG、JPEG、WebP、BMP、TIFF、GIF格式间转换
- 压缩优化:通过质量预设优化文件大小
- 滤镜效果:应用预设滤镜(灰度、复古棕、怀旧、模糊、锐化等)
- 批量处理:使用相同设置处理多张图像
Quick Start
快速开始
python
from scripts.image_enhancer import ImageEnhancerpython
from scripts.image_enhancer import ImageEnhancerSingle image processing
单张图像处理
enhancer = ImageEnhancer("photo.jpg")
enhancer.resize(width=800).sharpen(0.5).save("photo_enhanced.jpg")
enhancer = ImageEnhancer("photo.jpg")
enhancer.resize(width=800).sharpen(0.5).save("photo_enhanced.jpg")
Batch processing
批量处理
from scripts.image_enhancer import batch_process
batch_process(
input_dir="raw_photos/",
output_dir="processed/",
operations=[
("resize", {"width": 1200}),
("watermark", {"text": "© 2024"}),
("compress", {"quality": 85})
]
)
undefinedfrom scripts.image_enhancer import batch_process
batch_process(
input_dir="raw_photos/",
output_dir="processed/",
operations=[
("resize", {"width": 1200}),
("watermark", {"text": "© 2024"}),
("compress", {"quality": 85})
]
)
undefinedOperations Reference
操作参考
Resize
调整尺寸
python
undefinedpython
undefinedBy width (maintain aspect ratio)
按宽度调整(保留宽高比)
enhancer.resize(width=800)
enhancer.resize(width=800)
By height (maintain aspect ratio)
按高度调整(保留宽高比)
enhancer.resize(height=600)
enhancer.resize(height=600)
Exact dimensions (may distort)
精确尺寸(可能变形)
enhancer.resize(width=800, height=600, maintain_aspect=False)
enhancer.resize(width=800, height=600, maintain_aspect=False)
Fit within bounds
适配边界
enhancer.resize(max_width=1200, max_height=800)
enhancer.resize(max_width=1200, max_height=800)
Scale by percentage
按比例缩放
enhancer.resize(scale=0.5) # 50%
undefinedenhancer.resize(scale=0.5) # 50%
undefinedCrop
裁剪
python
undefinedpython
undefinedCrop to specific dimensions from center
从中心裁剪至特定尺寸
enhancer.crop(width=800, height=600)
enhancer.crop(width=800, height=600)
Crop with position
指定位置裁剪
enhancer.crop(width=800, height=600, position='top-left')
enhancer.crop(width=800, height=600, position='top-left')
Positions: 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right'
可选位置: 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right'
Crop to exact coordinates (left, top, right, bottom)
按精确坐标裁剪(左、上、右、下)
enhancer.crop(box=(100, 100, 900, 700))
enhancer.crop(box=(100, 100, 900, 700))
Smart crop (content-aware)
智能裁剪(内容识别)
enhancer.smart_crop(width=800, height=600)
undefinedenhancer.smart_crop(width=800, height=600)
undefinedWatermark
添加水印
python
undefinedpython
undefinedText watermark
文字水印
enhancer.watermark(
text="© 2024 Company",
position='bottom-right',
opacity=0.5,
font_size=24,
color='white'
)
enhancer.watermark(
text="© 2024 Company",
position='bottom-right',
opacity=0.5,
font_size=24,
color='white'
)
Image watermark
图片水印
enhancer.watermark(
image="logo.png",
position='bottom-right',
opacity=0.3,
scale=0.2 # 20% of main image width
)
enhancer.watermark(
image="logo.png",
position='bottom-right',
opacity=0.3,
scale=0.2 # 主图宽度的20%
)
Tiled watermark
平铺水印
enhancer.watermark(
text="DRAFT",
tiled=True,
opacity=0.1,
rotation=45
)
undefinedenhancer.watermark(
text="DRAFT",
tiled=True,
opacity=0.1,
rotation=45
)
undefinedColor Adjustments
色彩调整
python
undefinedpython
undefinedIndividual adjustments (range: -1.0 to 1.0, 0 = no change)
单独调整(范围: -1.0 至 1.0,0 = 无变化)
enhancer.brightness(0.2) # +20% brightness
enhancer.contrast(0.3) # +30% contrast
enhancer.saturation(-0.2) # -20% saturation
enhancer.sharpen(0.5) # Sharpen
enhancer.brightness(0.2) # 亮度+20%
enhancer.contrast(0.3) # 对比度+30%
enhancer.saturation(-0.2) # 饱和度-20%
enhancer.sharpen(0.5) # 锐化
Combined adjustment
组合调整
enhancer.adjust(
brightness=0.1,
contrast=0.2,
saturation=0.1,
sharpen=0.3
)
enhancer.adjust(
brightness=0.1,
contrast=0.2,
saturation=0.1,
sharpen=0.3
)
Auto-enhance
自动增强
enhancer.auto_enhance()
undefinedenhancer.auto_enhance()
undefinedFilters
滤镜
python
undefinedpython
undefinedApply preset filters
应用预设滤镜
enhancer.filter('grayscale')
enhancer.filter('sepia')
enhancer.filter('vintage')
enhancer.filter('blur')
enhancer.filter('sharpen')
enhancer.filter('edge_enhance')
enhancer.filter('emboss')
enhancer.filter('grayscale')
enhancer.filter('sepia')
enhancer.filter('vintage')
enhancer.filter('blur')
enhancer.filter('sharpen')
enhancer.filter('edge_enhance')
enhancer.filter('emboss')
Custom blur
自定义模糊
enhancer.blur(radius=2)
enhancer.blur(radius=2)
Gaussian blur
高斯模糊
enhancer.gaussian_blur(radius=3)
undefinedenhancer.gaussian_blur(radius=3)
undefinedFormat Conversion
格式转换
python
undefinedpython
undefinedConvert to different format
转换为不同格式
enhancer.save("output.png") # Auto-detect from extension
enhancer.save("output.webp")
enhancer.save("output.jpg")
enhancer.save("output.png") # 从扩展名自动识别
enhancer.save("output.webp")
enhancer.save("output.jpg")
Explicit format
显式指定格式
enhancer.convert('PNG').save("output.png")
enhancer.convert('WEBP').save("output.webp")
undefinedenhancer.convert('PNG').save("output.png")
enhancer.convert('WEBP').save("output.webp")
undefinedCompression
压缩
python
undefinedpython
undefinedJPEG quality (1-100)
JPEG质量(1-100)
enhancer.compress(quality=85).save("compressed.jpg")
enhancer.compress(quality=85).save("compressed.jpg")
WebP with quality
WebP质量设置
enhancer.save("output.webp", quality=80)
enhancer.save("output.webp", quality=80)
PNG optimization
PNG优化
enhancer.optimize_png().save("optimized.png")
enhancer.optimize_png().save("optimized.png")
Target file size
按目标文件大小压缩
enhancer.compress_to_size(max_kb=500).save("sized.jpg")
undefinedenhancer.compress_to_size(max_kb=500).save("sized.jpg")
undefinedQuality Presets
质量预设
python
undefinedpython
undefinedWeb optimized
网页优化预设
enhancer.preset('web') # 1200px max, 85 quality, WebP
enhancer.preset('web') # 最大1200px,质量85,WebP格式
Social media
社交媒体预设
enhancer.preset('instagram') # 1080x1080, optimized
enhancer.preset('twitter') # 1200x675
enhancer.preset('facebook') # 1200x630
enhancer.preset('linkedin') # 1200x627
enhancer.preset('instagram') # 1080x1080,优化格式
enhancer.preset('twitter') # 1200x675
enhancer.preset('facebook') # 1200x630
enhancer.preset('linkedin') # 1200x627
Print quality
印刷质量预设
enhancer.preset('print_4x6') # 1800x1200, 300dpi
enhancer.preset('print_8x10') # 3000x2400, 300dpi
enhancer.preset('print_4x6') # 1800x1200,300dpi
enhancer.preset('print_8x10') # 3000x2400,300dpi
Thumbnail
缩略图预设
enhancer.preset('thumbnail') # 150x150, center crop
enhancer.preset('preview') # 400px max, 70 quality
undefinedenhancer.preset('thumbnail') # 150x150,中心裁剪
enhancer.preset('preview') # 最大400px,质量70
undefinedBatch Processing
批量处理
Process Directory
处理目录
python
from scripts.image_enhancer import batch_processpython
from scripts.image_enhancer import batch_processApply same operations to all images
对所有图像应用相同操作
results = batch_process(
input_dir="photos/",
output_dir="processed/",
operations=[
("resize", {"width": 1200}),
("watermark", {"text": "© 2024", "position": "bottom-right"}),
("compress", {"quality": 85})
],
formats=['jpg', 'png'], # Only process these formats
recursive=True # Include subdirectories
)
print(f"Processed: {results['success']} images")
print(f"Failed: {results['failed']} images")
undefinedresults = batch_process(
input_dir="photos/",
output_dir="processed/",
operations=[
("resize", {"width": 1200}),
("watermark", {"text": "© 2024", "position": "bottom-right"}),
("compress", {"quality": 85})
],
formats=['jpg', 'png'], # 仅处理这些格式
recursive=True # 包含子目录
)
print(f"处理完成: {results['success']} 张图像")
print(f"处理失败: {results['failed']} 张图像")
undefinedRename Pattern
重命名规则
python
batch_process(
input_dir="photos/",
output_dir="processed/",
operations=[("resize", {"width": 800})],
rename_pattern="{name}_web_{index:03d}"
)python
batch_process(
input_dir="photos/",
output_dir="processed/",
operations=[("resize", {"width": 800})],
rename_pattern="{name}_web_{index:03d}"
)Output: photo_web_001.jpg, photo_web_002.jpg, ...
输出: photo_web_001.jpg, photo_web_002.jpg, ...
undefinedundefinedGenerate Multiple Sizes
生成多尺寸版本
python
from scripts.image_enhancer import generate_sizespython
from scripts.image_enhancer import generate_sizesCreate multiple sizes from one image
从单张图像生成多尺寸版本
sizes = generate_sizes(
"hero.jpg",
output_dir="responsive/",
widths=[320, 640, 1024, 1920],
format='webp'
)
sizes = generate_sizes(
"hero.jpg",
output_dir="responsive/",
widths=[320, 640, 1024, 1920],
format='webp'
)
Output: hero_320.webp, hero_640.webp, etc.
输出: hero_320.webp, hero_640.webp, 等
undefinedundefinedIcon Generation
图标生成
python
from scripts.image_enhancer import generate_iconspython
from scripts.image_enhancer import generate_iconsGenerate favicon and app icons from single image
从单张图像生成网站图标和应用图标
icons = generate_icons(
"logo.png",
output_dir="icons/",
sizes=[16, 32, 48, 64, 128, 256, 512]
)
undefinedicons = generate_icons(
"logo.png",
output_dir="icons/",
sizes=[16, 32, 48, 64, 128, 256, 512]
)
undefinedMetadata Operations
元数据操作
python
undefinedpython
undefinedRead EXIF data
读取EXIF数据
metadata = enhancer.get_metadata()
print(metadata['camera'])
print(metadata['date_taken'])
print(metadata['gps'])
metadata = enhancer.get_metadata()
print(metadata['camera'])
print(metadata['date_taken'])
print(metadata['gps'])
Strip metadata (privacy)
移除元数据(隐私保护)
enhancer.strip_metadata()
enhancer.strip_metadata()
Preserve specific metadata
保留指定元数据
enhancer.strip_metadata(keep=['copyright', 'artist'])
undefinedenhancer.strip_metadata(keep=['copyright', 'artist'])
undefinedCLI Usage
CLI 使用方式
bash
undefinedbash
undefinedSingle file
单文件处理
python image_enhancer.py input.jpg -o output.jpg --resize 800 --quality 85
python image_enhancer.py input.jpg -o output.jpg --resize 800 --quality 85
Batch processing
批量处理
python image_enhancer.py photos/ -o processed/ --resize 1200 --watermark "© 2024"
python image_enhancer.py photos/ -o processed/ --resize 1200 --watermark "© 2024"
Apply preset
应用预设
python image_enhancer.py photo.jpg --preset instagram
python image_enhancer.py photo.jpg --preset instagram
Generate icons
生成图标
python image_enhancer.py logo.png --icons icons/
undefinedpython image_enhancer.py logo.png --icons icons/
undefinedSupported Formats
支持的格式
| Format | Read | Write | Notes |
|---|---|---|---|
| JPEG | Yes | Yes | Lossy, best for photos |
| PNG | Yes | Yes | Lossless, supports transparency |
| WebP | Yes | Yes | Modern format, good compression |
| GIF | Yes | Yes | Animation support |
| BMP | Yes | Yes | Uncompressed |
| TIFF | Yes | Yes | High quality, large files |
| ICO | Yes | Yes | Icon format |
| HEIC | Yes | No | iPhone photos (read only) |
| 格式 | 读取 | 写入 | 说明 |
|---|---|---|---|
| JPEG | 是 | 是 | 有损压缩,适合照片 |
| PNG | 是 | 是 | 无损压缩,支持透明 |
| WebP | 是 | 是 | 现代格式,压缩率高 |
| GIF | 是 | 是 | 支持动画 |
| BMP | 是 | 是 | 无压缩 |
| TIFF | 是 | 是 | 高质量,文件较大 |
| ICO | 是 | 是 | 图标格式 |
| HEIC | 是 | 否 | iPhone照片(仅支持读取) |
Error Handling
错误处理
python
from scripts.image_enhancer import ImageEnhancer, ImageError
try:
enhancer = ImageEnhancer("photo.jpg")
enhancer.resize(width=800).save("output.jpg")
except ImageError as e:
print(f"Image error: {e}")
except FileNotFoundError:
print("Image file not found")python
from scripts.image_enhancer import ImageEnhancer, ImageError
try:
enhancer = ImageEnhancer("photo.jpg")
enhancer.resize(width=800).save("output.jpg")
except ImageError as e:
print(f"图像错误: {e}")
except FileNotFoundError:
print("未找到图像文件")Configuration
配置
python
enhancer = ImageEnhancer("photo.jpg")python
enhancer = ImageEnhancer("photo.jpg")Global settings
全局设置
enhancer.config.update({
'default_quality': 85,
'default_format': 'webp',
'preserve_metadata': False,
'color_profile': 'sRGB',
'dpi': 72
})
undefinedenhancer.config.update({
'default_quality': 85,
'default_format': 'webp',
'preserve_metadata': False,
'color_profile': 'sRGB',
'dpi': 72
})
undefinedPerformance Tips
性能优化技巧
- Large batches: Use with
batch_process()parallel=True - Memory: Process one image at a time for very large files
- Speed: WebP encoding is slower but produces smaller files
- Quality: Start at 85 quality, reduce if file size is critical
- 大批量处理:使用并设置
batch_process()parallel=True - 内存管理:处理超大文件时,一次只处理一张图像
- 速度平衡:WebP编码速度较慢但文件更小
- 质量控制:从85质量开始,若文件大小优先级更高则降低质量
Dependencies
依赖项
pillow>=10.0.0
opencv-python>=4.8.0
numpy>=1.24.0pillow>=10.0.0
opencv-python>=4.8.0
numpy>=1.24.0