Loading...
Loading...
Compare original and translation side by side
| Operation | Method | Description |
|---|---|---|
| Loading | | Load from URL, path, bytes, or base64 |
| Download image from URL | |
| Saving | | Save with format auto-detection |
| Convert to bytes | |
| Convert to base64 string | |
| Resizing | | Resize to exact dimensions |
| Scale by factor (0.5 = half) | |
| Fit within size, maintain aspect | |
| Cropping | | Crop to region |
| Crop from center | |
| Crop to aspect ratio | |
| Compositing | | Overlay at coordinates |
| Alpha composite | |
| Fit onto canvas size | |
| Borders | | Add solid border |
| Add whitespace padding | |
| Transforms | | Rotate by degrees |
| Mirror horizontally | |
| Flip vertically | |
| Watermarks | | Add text overlay |
| Add logo watermark | |
| Adjustments | | Lighten/darken |
| Adjust contrast | |
| Adjust color saturation | |
| Apply Gaussian blur | |
| Web | | Optimize for delivery |
| Info | | Get dimensions, format, mode |
| 操作 | 方法 | 描述 |
|---|---|---|
| 加载 | | 从URL、路径、字节或base64加载图像 |
| 从URL下载图像 | |
| 保存 | | 自动检测格式保存图像 |
| 将图像转换为字节格式 | |
| 将图像转换为base64字符串 | |
| 调整大小 | | 调整至精确尺寸 |
| 按比例缩放(0.5为原尺寸的一半) | |
| 适配指定尺寸,保持宽高比 | |
| 裁剪 | | 裁剪指定区域 |
| 从中心裁剪 | |
| 裁剪至指定宽高比 | |
| 合成 | | 在指定坐标叠加前景图 |
| Alpha通道合成 | |
| 将图像适配至画布尺寸 | |
| 边框 | | 添加纯色边框 |
| 添加空白内边距 | |
| 变换 | | 按角度旋转 |
| 水平镜像翻转 | |
| 垂直翻转 | |
| 水印 | | 添加文字水印 |
| 添加Logo水印 | |
| 色彩调整 | | 调整亮度(提亮/变暗) |
| 调整对比度 | |
| 调整色彩饱和度 | |
| 应用高斯模糊 | |
| Web优化 | | 优化以适配Web传输 |
| 信息获取 | | 获取图像尺寸、格式、色彩模式 |
pip install Pillow requestspip install Pillow requestsfrom image_utils import ImageUtilsfrom image_utils import ImageUtilsundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedfrom bria_client import BriaClient
from image_utils import ImageUtils
client = BriaClient()from bria_client import BriaClient
from image_utils import ImageUtils
client = BriaClient()undefinedundefinedfrom pathlib import Path
from image_utils import ImageUtils
def process_catalog(input_dir, output_dir):
"""Process all images in a directory."""
output_path = Path(output_dir)
output_path.mkdir(exist_ok=True)
for image_file in Path(input_dir).glob("*.{jpg,png,webp}"):
image = ImageUtils.load(image_file)
# Crop to square
square = ImageUtils.crop_to_aspect(image, "1:1")
# Resize to standard size
resized = ImageUtils.resize(square, width=800, height=800)
# Add watermark
final = ImageUtils.add_text_watermark(resized, "© My Brand")
# Save optimized
output_file = output_path / f"{image_file.stem}.webp"
ImageUtils.save(final, output_file, quality=85)
process_catalog("./raw_images", "./processed")from pathlib import Path
from image_utils import ImageUtils
def process_catalog(input_dir, output_dir):
"""处理目录中的所有图像。"""
output_path = Path(output_dir)
output_path.mkdir(exist_ok=True)
for image_file in Path(input_dir).glob("*.{jpg,png,webp}"):
image = ImageUtils.load(image_file)
# 裁剪为正方形
square = ImageUtils.crop_to_aspect(image, "1:1")
# 调整至标准尺寸
resized = ImageUtils.resize(square, width=800, height=800)
# 添加水印
final = ImageUtils.add_text_watermark(resized, "© My Brand")
# 保存为优化后的格式
output_file = output_path / f"{image_file.stem}.webp"
ImageUtils.save(final, output_file, quality=85)
process_catalog("./raw_images", "./processed")