Feature Overview
Use OpenAI’s standard image editing API through LaoZhang API to edit and modify existing images. This documentation explains how to use the Image Edit API for professional image editing.Introduction
The Image Edit API allows you to edit specific parts of an image by providing the original image, a mask, and a text prompt. This feature is particularly suitable for:- Localized Modifications: Only modify specific regions of an image
- Content Replacement: Replace certain elements in an image
- Creative Editing: Add new elements while maintaining overall style
- Image Restoration: Repair or improve specific parts of an image
API Working Principle
Image editing requires three key elements:- Original Image: The base image to edit
- Mask Image: Specifies the region to edit (transparent areas will be edited)
- Prompt: Describes what you want to generate in the edited region
Transparent areas (alpha channel = 0) in the mask image will be identified as parts to edit. Fully opaque areas will remain unchanged.
Quick Start
Basic Configuration
Basic Editing Example
API Parameters
Request Parameters
Response Format
Creating Mask Images
Using Python PIL to Create Masks
Using Circular Mask
Complete Usage Examples
Complete Python Example
Node.js Example
Practical Application Scenarios
1. Background Replacement
2. Object Removal
3. Clothing Change
4. Image Restoration
Advanced Techniques
1. Feathered Mask
Create mask with feathered edges for more natural edits:2. Multi-Region Editing
Edit multiple regions simultaneously:3. Smart Prompt Building
Best Practices
1. Image Preparation
- Format Requirement: Ensure image is PNG format
- Size Requirement: Image must be square
- File Size: Under 4MB
- Resolution Recommendation: Use 1024x1024 for best results
2. Mask Design
- Precise Masks: More precise masks yield better editing results
- Edge Handling: Consider using feathered edges for more natural edits
- Region Size: Avoid overly large edit regions, may affect results
3. Prompt Optimization
4. Error Handling
FAQ
Q: Why don’t edit results match expectations?
A: Check if mask is correct, ensuring transparent areas accurately cover parts to edit. Also optimize prompt for more specific descriptions.Q: Which image formats are supported?
A: Currently only PNG format is supported, and images must be square.Q: How to achieve more natural edit results?
A: Use feathered masks and emphasize “natural blending”, “matching surrounding environment” in prompts.Q: Can multiple regions be edited simultaneously?
A: Yes, simply mark multiple transparent areas in the mask.Q: What limitations exist when editing large images?
A: Image files must be under 4MB, compression before upload is recommended.Related Resources
The Image Edit API is particularly suitable for scenarios requiring precise control over edit regions. Through proper mask design and prompt optimization, professional-grade image editing results can be achieved.