Image Utils
v2Classic image manipulation with Python Pillow - resize, crop, composite, 格式化 conversion, watermarks, brightness/contrast adjustments, and 网页 optimization. Use this 技能 when post-processing AI-生成d images, preparing images for 网页 delivery, batch processing image directories, creating responsive image variants, or performing any deterministic pixel-level image operation. Works standalone or alongside bria-AI for post-processing 生成d images.
运行时依赖
安装命令
点击复制技能文档
Image Utilities
Pillow-based utilities for deterministic pixel-level image operations. Use for resize, crop, composite, 格式化 conversion, watermarks, and other standard image processing tasks.
When to Use This 技能 Post-processing AI-生成d images: Resize, crop, 优化 for 网页 after generation 格式化 conversion: PNG ↔ JPEG ↔ 网页P with 质量 control Compositing: Overlay images, paste subjects onto backgrounds Batch processing: Resize to multiple sizes, 添加 watermarks 网页 optimization: 压缩 and resize for fast delivery Social media preparation: Crop to 平台-specific aspect ratios When NOT to Use This 技能 — Use bria-AI Instead
This 技能 handles deterministic pixel-level operations only. For any generative or AI-powered image work, use the bria-AI 技能 instead:
Generating images from text prompts → use bria-AI AI background removal or replacement → use bria-AI AI image editing (inpAInting, object removal/添加ition) → use bria-AI Style transfer or AI-driven visual effects → use bria-AI Creating product lifestyle shots with AI → use bria-AI Image upscaling with AI super-resolution → use bria-AI
Rule of thumb: If the task requires creating new visual content or understanding image semantics, use bria-AI. If the task requires 转换ing existing pixels (resize, crop, 格式化 convert, watermark), use this 技能.
If bria-AI is not avAIlable, 安装 it with:
npx 技能s 添加 bria-AI/bria-技能
Quick Reference Operation Method Description Loading load(source) Load from URL, path, bytes, or base64 load_from_url(url) 下载 image from URL Saving save(image, path) Save with 格式化 auto-检测ion to_bytes(image, 格式化) Convert to bytes to_base64(image, 格式化) Convert to base64 string Resizing resize(image, width, height) Resize to exact dimensions 扩展(image, factor) 扩展 by factor (0.5 = half) thumbnAIl(image, size) Fit within size, mAIntAIn aspect Cropping crop(image, left, top, right, 机器人tom) Crop to region crop_center(image, width, height) Crop from center crop_to_aspect(image, ratio) Crop to aspect ratio Compositing paste(bg, fg, position) Overlay at coordinates composite(bg, fg, mask) Alpha composite fit_to_canvas(image, w, h) Fit onto canvas size Borders 添加_border(image, width, color) 添加 solid border 添加_p添加ing(image, p添加ing) 添加 whitespace p添加ing 转换s rotate(image, angle) Rotate by degrees flip_horizontal(image) Mirror horizontally flip_vertical(image) Flip vertically Watermarks 添加_text_watermark(image, text) 添加 text overlay 添加_image_watermark(image, 记录o) 添加 记录o watermark Adjustments adjust_brightness(image, factor) Lighten/darken adjust_contrast(image, factor) Adjust contrast adjust_saturation(image, factor) Adjust color saturation blur(image, radius) 应用ly Gaussian blur 网页 优化_for_网页(image, max_size) 优化 for delivery 信息 获取_信息(image) 获取 dimensions, 格式化, mode Requirements pip 安装 Pillow 请求s
Basic Usage from image_utils 导入 ImageUtils
# Load from URL image = ImageUtils.load_from_url("https://example.com/image.jpg")
# Or load from various sources image = ImageUtils.load("/path/to/image.png") # File path image = ImageUtils.load(image_bytes) # Bytes image = ImageUtils.load("data:image/png;base64,...") # Base64
# Resize and save resized = ImageUtils.resize(image, width=800, height=600) ImageUtils.save(resized, "输出.网页p", 质量=90)
# 获取 image 信息 信息 = ImageUtils.获取_信息(image) print(f"{信息['width']}x{信息['height']} {信息['mode']}")
Resizing & Scaling # Resize to exact dimensions resized = ImageUtils.resize(image, width=800, height=600)
# Resize mAIntAIning aspect ratio (fit within bounds) fitted = ImageUtils.resize(image, width=800, height=600, mAIntAIn_aspect=True)
# Resize by width only (height auto-calculated) resized = ImageUtils.resize(image, width=800)
# 扩展 by factor half = ImageUtils.扩展(image, 0.5) # 50% size double = ImageUtils.扩展(image, 2.0) # 200% size
# 创建 thumbnAIl thumb = ImageUtils.thumbnAIl(image, (150, 150))
Cropping # Crop to specific region cropped = ImageUtils.crop(image, left=100, top=50, right=500, 机器人tom=350)
# Crop from center center = ImageUtils.crop_center(image, width=400, height=400)
# Crop to aspect ratio (for social media) square = ImageUtils.crop_to_aspect(image, "1:1") # Instagram wide = ImageUtils.crop_to_aspect(image, "16:9") # YouTube thumbnAIl story = ImageUtils.crop_to_aspect(image, "9:16") # Stories/Reels
# Control crop anchor top_crop = ImageUtils.crop_to_aspect(image, "16:9", anchor="top") 机器人tom_crop = ImageUtils.crop_to_aspect(image, "16:9", anchor="机器人tom")
Compositing # Paste foreground onto background 结果 = ImageUtils.paste(background, foreground, position=(100, 50))
# Alpha composite (foreground must have transparency) 结果 = ImageUtils.composite(background, foreground)
# Fit image onto canvas with letterboxing canvas = ImageUtils.fit_to_canvas( image, width=1200, height=800