image-edit
Use this skill for all image editing and enhancement requests on Starchild.
Covers: general editing, background replacement, super-resolution, old photo restoration, colorization, person removal, portrait retouching (skin smoothing, blemish removal, teeth whitening), slimming, color grading, artistic filters, image blending, outpainting, local editing, text rendering, multi-angle generation, before/after comparison, car recoloring, car wrap preview, and fitness/medical transformation comparisons.
Core principle: call the provided script. Do not re-implement proxy/billing plumbing.
When to use image-edit vs other image skills:
- image-edit → user wants to EDIT, ENHANCE, or TRANSFORM an existing image
- image-portrait → user wants a portrait with their face/identity preserved from a reference photo
- image-create → user wants to CREATE something from a text description (no source image)
1. Quick start — basic edit (most common)
⚠️ Execution context — read this first.
The code blocks below are Python, not shell commands. Starchild's bash tool
runs /bin/bash -c, which cannot parse exec(open(...)) — pasting them directly
into a bash command will fail with syntax error near unexpected token 'open'.
Also, exec(open(...)) inside python3 -c fails with NameError: __file__
because the script uses __file__ for path resolution.
Use python3 - <<'EOF' with from exports import when calling via the bash tool:
python3 - <<'EOF'
import sys
sys.path.insert(0, "skills/image-edit")
from exports import edit_image
result = edit_image(
image_path="uploads/photo.jpg",
prompt="make the sky more dramatic with golden sunset colors",
action="enhance",
)
print(result)
EOF
The heredoc (<<'EOF') preserves all quotes and newlines — no escaping needed.
exec(open('skills/image-edit/edit_image.py').read())
result = edit_image(
image_path="uploads/photo.jpg",
prompt="make the sky more dramatic with golden sunset colors",
action="enhance",
)
# result -> {"success": True, "images": [{"local_path": "output/images/..."}], ...}
The script reads the local file, base64-encodes it, and sends it to fal.ai as a data URI — no manual URL publishing needed.
2. Quick start — public URL
exec(open('skills/image-edit/edit_image.py').read())
result = edit_image(
image_url="https://example.com/photo.jpg",
prompt="replace the background with a tropical beach",
action="replace_bg",
)
Delivering the result to the user — IMPORTANT
Never hand the user the raw fal.media URL. fal serves files with restrictive CSP headers. The only reliable delivery path is the already-downloaded local file:
- Use each image's
local_path (e.g. output/images/xxx.png) — the script always downloads on success.
- Tell the user the files are saved to
output/images/ and viewable in the workspace file panel.
- On Web channel, embed inline so the user can preview in chat:

- On Telegram / WeChat: send via
send_to_telegram(file_path="output/images/...", message_type="image") or send_to_wechat(file_path="output/images/...", message_type="image").
3. Parameters
| Parameter |
Required |
Default |
Description |
image_path |
yes* |
— |
Local workspace file path to the source image |
image_url |
yes* |
— |
Public HTTPS URL of the source image |
prompt |
no |
auto |
Editing instruction (what to change) |
action |
no |
"edit" |
Operation type (see §4) |
model |
no |
"nanopro" |
Model: "nanopro" (fast ~25s) or "gpt" (best quality ~150s) |
aspect_ratio |
no |
None |
Output ratio: 1:1, 3:4, 4:3, 9:16, 16:9. None = preserve original. |
*At least one of image_path or image_url must be provided. If both are given, image_path takes priority.
4. Actions — operation types
F: Multi-image / general editing
| Action |
Key |
Description |
| General edit |
edit |
Modify the image according to the prompt |
| Image blending |
blend |
Place a person/subject into a new background or scene |
| Outpainting |
extend |
Extend the image beyond its current boundaries |
| Local edit |
local_edit |
Modify only a specific region of the image |
| Structural redesign |
restructure |
Change layout/grid/column count or rearrange elements — overrides "preserve composition" |
| Text rendering |
text_render |
Add or modify text within the image |
| Multi-angle |
multi_angle |
Generate different viewing angles from one photo |
| Before/after |
before_after |
Generate a side-by-side comparison image |
G: Professional editing
| Action |
Key |
Description |
| Background replacement |
replace_bg |
Swap the background while keeping the subject |
| Super-resolution |
upscale |
Upscale and enhance image resolution |
| Photo restoration |
restore |
Repair scratches, tears, fading in old photos |
| Colorization |
colorize |
Add realistic colors to black-and-white photos |
| Person removal |
remove_person |
Remove a specific person from the photo |
V: Retouching / beauty
| Action |
Key |
Description |
| Portrait retouching |
retouch |
Skin smoothing, blemish removal, teeth whitening |
| Slimming |
slim |
Adjust facial and body proportions subtly |
| Enhancement |
enhance |
Color correction, lighting improvement, quality boost |
| Artistic filter |
filter |
Apply a specific artistic style or filter effect |
W: Medical / fitness comparison
| Action |
Key |
Description |
| Transformation comparison |
comparison |
Before/after for medical, fitness, or transformation |
X: Automotive
| Action |
Key |
Description |
| Car recolor |
car_color |
Change the color of a vehicle |
| Car wrap preview |
car_wrap |
Visualize a wrap or film on a vehicle |
5. Model selection guide
| Model |
Key |
Speed |
Quality |
Best for |
| NanoPro |
nanopro |
~25s |
Good |
Default for all requests. Fast iteration. |
| GPT Image 2 |
gpt |
~150s |
Best |
When user explicitly asks for "highest quality" or "best quality". Complex edits. |
Decision rules:
- Default: always use
nanopro unless the user explicitly requests higher quality.
- Use
gpt when: user says "highest quality", "best quality", "premium", or the edit requires very precise detail preservation (e.g., complex text rendering, fine inpainting).
- Use
nanopro when: user wants fast results, is iterating on edits, or the edit is straightforward.
# Default (fast)
result = edit_image(image_path="photo.jpg", prompt="remove background", action="replace_bg")
# High quality (user requested)
result = edit_image(image_path="photo.jpg", prompt="remove background", action="replace_bg", model="gpt")
6. Intent recognition guide
Use this table to map user requests to the correct action:
General editing
| User says |
Action |
Prompt hint |
| "edit this photo", "modify this image" |
edit |
Pass user's instruction as prompt |
| "put me on a beach", "change the scene" |
blend |
Describe the target scene |
| "extend the image", "make it wider", "outpaint" |
extend |
Describe what to add |
| "change just the shirt color", "edit only the sky" |
local_edit |
Specify the region and change |
| "fewer columns", "simplify the grid", "rearrange the layout", "make it 7 columns max" |
restructure |
State the target structure explicitly (rows/columns/arrangement) |
| "add text", "write 'Hello' on the image" |
text_render |
Specify text content and placement |
| "show from the side", "different angle" |
multi_angle |
Describe the desired angle |
| "before and after", "show the difference" |
before_after |
Describe the transformation |
Professional editing
| User says |
Action |
Prompt hint |
| "remove background", "change background", "换背景" |
replace_bg |
Describe the new background |
| "upscale", "make it higher resolution", "enhance quality" |
upscale |
Optionally specify target quality |
| "restore old photo", "fix this damaged photo", "修复老照片" |
restore |
Describe specific damage to fix |
| "colorize", "add color to B&W photo", "上色" |
colorize |
Optionally describe expected colors |
| "remove this person", "P掉某人" |
remove_person |
Describe which person to remove |
Retouching / beauty
| User says |
Action |
Prompt hint |
| "retouch", "smooth skin", "remove blemishes", "磨皮美白" |
retouch |
Specify retouching level |
| "make me thinner", "slim face", "瘦脸" |
slim |
Specify areas to adjust |
| "enhance colors", "improve lighting", "调色" |
enhance |
Describe desired look |
| "apply filter", "make it look vintage", "滤镜" |
filter |
Describe the filter style |
Medical / fitness
| User says |
Action |
Prompt hint |
| "before and after surgery", "fitness transformation" |
comparison |
Describe the transformation context |
Automotive
| User says |
Action |
Prompt hint |
| "change car color", "make it red", "汽车改色" |
car_color |
Specify the target color and finish |
| "car wrap", "vinyl wrap preview", "贴膜预览" |
car_wrap |
Describe wrap material and color |
7. Prompt engineering best practices
The prompt template system
Every action has a built-in prompt template that wraps the user's instruction for optimal results. You only need to pass the user's specific intent — the template adds the technical quality instructions automatically.
For example, if the user says "make the background a sunset beach":
result = edit_image(
image_path="photo.jpg",
prompt="a beautiful sunset beach with palm trees and golden light",
action="replace_bg",
)
# The script wraps this into: "Replace the background of this image: a beautiful
# sunset beach with palm trees and golden light. Keep the foreground subject
# perfectly intact with clean edges. Match the lighting direction..."
Key principles (from reference skills)
Be specific about the change — vague prompts produce poor results:
- ❌ "make it better"
- ✅ "increase contrast, add warm golden tones, sharpen details"
Describe what to preserve — especially for local edits:
- ❌ "change the shirt"
- ✅ "change the shirt color to navy blue, keep the same fabric texture and wrinkles"
Specify materials and finishes — for car and product edits:
- ❌ "make it blue"
- ✅ "deep metallic blue with a glossy clear coat finish"
Reference real-world styles — for filters and artistic effects:
- ❌ "make it artistic"
- ✅ "apply a warm cinematic color grade like Wes Anderson films"
Describe the era for restoration/colorization:
- ❌ "colorize this"
- ✅ "colorize this 1940s family portrait with period-appropriate clothing colors"
For retouching, specify the level:
- Light: "subtle skin smoothing, keep natural texture"
- Medium: "professional retouching, remove blemishes, even skin tone"
- Heavy: "full beauty retouching, smooth skin, brighten eyes, whiten teeth"
8. Usage examples by scenario
Background replacement
exec(open('skills/image-edit/edit_image.py').read())
# Simple background swap
result = edit_image(
image_path="uploads/portrait.jpg",
prompt="a modern office with floor-to-ceiling windows and city skyline view",
action="replace_bg",
)
# Studio background
result = edit_image(
image_path="uploads/product.jpg",
prompt="clean white studio background with soft shadow",
action="replace_bg",
)
Old photo restoration
# Repair damaged photo
result = edit_image(
image_path="uploads/old_family_photo.jpg",
prompt="repair all scratches, tears, and stains; restore faded colors; enhance clarity",
action="restore",
)
# Colorize black-and-white photo
result = edit_image(
image_path="uploads/grandpa_1945.jpg",
prompt="colorize with historically accurate colors for 1940s era, natural skin tones, period-appropriate clothing",
action="colorize",
)
Portrait retouching
# Professional retouching
result = edit_image(
image_path="uploads/selfie.jpg",
prompt="professional portrait retouching: smooth skin while keeping natural texture, remove blemishes, subtle teeth whitening, brighten eyes",
action="retouch",
)
# Slimming
result = edit_image(
image_path="uploads/photo.jpg",
prompt="subtle facial slimming, slightly more defined jawline, natural proportions",
action="slim",
)
Image enhancement
# Color grading
result = edit_image(
image_path="uploads/landscape.jpg",
prompt="cinematic color grading with warm golden tones, enhanced contrast, vibrant but natural colors",
action="enhance",
)
# Artistic filter
result = edit_image(
image_path="uploads/photo.jpg",
prompt="oil painting style with visible brushstrokes, rich warm palette, impressionist feel",
action="filter",
)
Super-resolution upscaling
result = edit_image(
image_path="uploads/low_res.jpg",
prompt="upscale to maximum quality, enhance fine details, reduce noise and compression artifacts",
action="upscale",
)
Person removal
result = edit_image(
image_path="uploads/group_photo.jpg",
prompt="remove the person on the far right, fill with the park background seamlessly",
action="remove_person",
)
Outpainting (image extension)
result = edit_image(
image_path="uploads/cropped.jpg",
prompt="extend the image to the left and right, continuing the mountain landscape naturally",
action="extend",
aspect_ratio="16:9",
)
Car customization
# Car recolor
result = edit_image(
image_path="uploads/my_car.jpg",
prompt="change to a deep cherry red metallic paint with glossy clear coat",
action="car_color",
)
# Car wrap preview
result = edit_image(
image_path="uploads/my_car.jpg",
prompt="matte black vinyl wrap with carbon fiber accents on the hood and mirrors",
action="car_wrap",
)
Before/after comparison
# Fitness transformation
result = edit_image(
image_path="uploads/fitness_photo.jpg",
prompt="create a fitness transformation comparison showing a more toned and fit version",
action="comparison",
)
Local editing
# Change specific element
result = edit_image(
image_path="uploads/outfit.jpg",
prompt="change only the dress color from red to emerald green, keep the same fabric texture",
action="local_edit",
)
Text rendering
result = edit_image(
image_path="uploads/poster_bg.jpg",
prompt="add the text 'SUMMER SALE' in bold white letters centered at the top, with a subtle drop shadow",
action="text_render",
)
High quality edit
# Use GPT model for best quality
result = edit_image(
image_path="uploads/important_photo.jpg",
prompt="professional color correction and enhancement for print publication",
action="enhance",
model="gpt",
)
9. Provided scripts
| File |
Purpose |
edit_image.py |
Core script: resolve image → build prompt → submit → poll → download. Handles local files (base64) and URLs, all actions, two models. |
exports.py |
Re-exports edit_image, ACTIONS, ACTION_PROMPTS, MODELS for programmatic use by other skills. |
_cost_track.py |
Cost tracking helper — records per-call costs via sc-proxy headers. |
10. Local testing
Set FAL_KEY env var to call fal.ai directly (bypasses sc-proxy):
# Basic edit
FAL_KEY=your-fal-key python3 skills/image-edit/edit_image.py photo.jpg "make it brighter" enhance nanopro
# Args: <image_path_or_url> [prompt] [action] [model]
11. Troubleshooting
| Problem |
Fix |
File not found: ... |
Check the workspace path; the file must exist |
Unsupported image format |
Use .jpg, .jpeg, .png, .webp, or .bmp |
Image too large |
Resize to under 10 MB before uploading |
image_url must be a public HTTP(S) URL |
Use image_path for local files, or provide a valid https:// URL |
Unknown action |
Check valid actions in §4 |
HTTP 402 insufficient_credits |
Top up balance; cost is pre-charged on submit |
HTTP 403 endpoint_not_allowed |
sc-proxy only allows approved fal endpoints; contact admin |
Edit FAILED upstream |
Simplify prompt, ensure source image is clear, retry |
Job stuck IN_PROGRESS >10 min |
Save request_id, retry later |
| Poor edit quality |
Try model="gpt" for higher quality; be more specific in prompt |
| Layout/grid/column count won't change no matter how many times you iterate |
Prefer action="restructure" for structural changes — its template mandates the layout change. Plain edit now has a precedence fallback (explicit structural instructions override composition preservation), but treat it only as a compatibility net, not the primary path |
| Background not fully removed |
Use replace_bg action with explicit background description |
| Retouching looks unnatural |
Add "keep natural texture" or "subtle" to prompt |
12. Infrastructure (reference)
- Caller →
sc-proxy → queue.fal.run/{model} → fal model providers
- All requests must include
Authorization: Key fake-falai-key-12345 (proxy injects the real FAL_KEY)
- Pre-charge happens at submit. Poll/result calls are free.
- Local files are base64-encoded as data URIs — no separate upload step needed.
- Final images live at
https://*.fal.media/... — public CDN, no auth needed for download.
- Cost tracking via
_cost_track.py — records X-Credits-Used from sc-proxy response headers.
Model endpoints
| Model |
Edit endpoint |
| nanopro |
fal-ai/nano-banana-pro/edit |
| gpt |
openai/gpt-image-2/edit |
1---2name: image-edit-23description: Image editing and enhancement of an existing image. Covers background replacement, super-resolution upscaling, old photo restoration, colorization, person removal, portrait retouching (skin smoothing, blemish removal), slimming, color grading, artistic filters, image blending, outpainting, local editing, text rendering, multi-angle generation, before/after comparison, car recoloring, car wrap preview. Use when editing, enhancing, or transforming an existing image (e.g. remove background, upscale photo, restore old photo, retouch portrait, change car color, apply filter, extend image).4---5
6# image-edit
7
8Use this skill for **all image editing and enhancement requests** on Starchild.
9
10Covers: general editing, background replacement, super-resolution, old photo restoration, colorization, person removal, portrait retouching (skin smoothing, blemish removal, teeth whitening), slimming, color grading, artistic filters, image blending, outpainting, local editing, text rendering, multi-angle generation, before/after comparison, car recoloring, car wrap preview, and fitness/medical transformation comparisons.
11
12**Core principle:** call the provided script. Do not re-implement proxy/billing plumbing.
13
14**When to use image-edit vs other image skills:**
15- **image-edit** → user wants to EDIT, ENHANCE, or TRANSFORM an existing image
16- **image-portrait** → user wants a portrait with their face/identity preserved from a reference photo
17- **image-create** → user wants to CREATE something from a text description (no source image)
18
19---
20
21## 1. Quick start — basic edit (most common)
22
23> **⚠️ Execution context — read this first.**
24> The code blocks below are **Python**, not shell commands. Starchild's `bash` tool
25> runs `/bin/bash -c`, which cannot parse `exec(open(...))` — pasting them directly
26> into a bash command will fail with `syntax error near unexpected token 'open'`.
27> Also, `exec(open(...))` inside `python3 -c` fails with `NameError: __file__`
28> because the script uses `__file__` for path resolution.
29>
30> **Use `python3 - <<'EOF'` with `from exports import` when calling via the bash tool:**
31>
32> ```bash
33> python3 - <<'EOF'
34> import sys
35> sys.path.insert(0, "skills/image-edit")
36> from exports import edit_image
37> result = edit_image(
38> image_path="uploads/photo.jpg",
39> prompt="make the sky more dramatic with golden sunset colors",
40> action="enhance",
41> )
42> print(result)
43> EOF
44> ```
45>
46> The heredoc (`<<'EOF'`) preserves all quotes and newlines — no escaping needed.
47
48```python
49exec(open('skills/image-edit/edit_image.py').read())
50result = edit_image(
51 image_path="uploads/photo.jpg",
52 prompt="make the sky more dramatic with golden sunset colors",
53 action="enhance",
54)
55# result -> {"success": True, "images": [{"local_path": "output/images/..."}], ...}
56```
57
58The script reads the local file, base64-encodes it, and sends it to fal.ai as a data URI — no manual URL publishing needed.
59
60## 2. Quick start — public URL
61
62```python
63exec(open('skills/image-edit/edit_image.py').read())
64result = edit_image(
65 image_url="https://example.com/photo.jpg",
66 prompt="replace the background with a tropical beach",
67 action="replace_bg",
68)
69```
70
71### Delivering the result to the user — IMPORTANT
72
73**Never hand the user the raw fal.media URL.** fal serves files with restrictive CSP headers. The only reliable delivery path is the **already-downloaded local file**:
74
751. Use each image's `local_path` (e.g. `output/images/xxx.png`) — the script always downloads on success.
762. Tell the user the files are saved to `output/images/` and viewable in the workspace file panel.
773. On Web channel, embed inline so the user can preview in chat:
78 ```markdown
79 
80 ```
814. On Telegram / WeChat: send via `send_to_telegram(file_path="output/images/...", message_type="image")` or `send_to_wechat(file_path="output/images/...", message_type="image")`.
82
83---
84
85## 3. Parameters
86
87| Parameter | Required | Default | Description |
88|-----------|----------|---------|-------------|
89| `image_path` | yes* | — | Local workspace file path to the source image |
90| `image_url` | yes* | — | Public HTTPS URL of the source image |
91| `prompt` | no | auto | Editing instruction (what to change) |
92| `action` | no | `"edit"` | Operation type (see §4) |
93| `model` | no | `"nanopro"` | Model: `"nanopro"` (fast ~25s) or `"gpt"` (best quality ~150s) |
94| `aspect_ratio` | no | `None` | Output ratio: `1:1`, `3:4`, `4:3`, `9:16`, `16:9`. `None` = preserve original. |
95
96*At least one of `image_path` or `image_url` must be provided. If both are given, `image_path` takes priority.
97
98---
99
100## 4. Actions — operation types
101
102### F: Multi-image / general editing
103
104| Action | Key | Description |
105|--------|-----|-------------|
106| General edit | `edit` | Modify the image according to the prompt |
107| Image blending | `blend` | Place a person/subject into a new background or scene |
108| Outpainting | `extend` | Extend the image beyond its current boundaries |
109| Local edit | `local_edit` | Modify only a specific region of the image |
110| Structural redesign | `restructure` | Change layout/grid/column count or rearrange elements — overrides "preserve composition" |
111| Text rendering | `text_render` | Add or modify text within the image |
112| Multi-angle | `multi_angle` | Generate different viewing angles from one photo |
113| Before/after | `before_after` | Generate a side-by-side comparison image |
114
115### G: Professional editing
116
117| Action | Key | Description |
118|--------|-----|-------------|
119| Background replacement | `replace_bg` | Swap the background while keeping the subject |
120| Super-resolution | `upscale` | Upscale and enhance image resolution |
121| Photo restoration | `restore` | Repair scratches, tears, fading in old photos |
122| Colorization | `colorize` | Add realistic colors to black-and-white photos |
123| Person removal | `remove_person` | Remove a specific person from the photo |
124
125### V: Retouching / beauty
126
127| Action | Key | Description |
128|--------|-----|-------------|
129| Portrait retouching | `retouch` | Skin smoothing, blemish removal, teeth whitening |
130| Slimming | `slim` | Adjust facial and body proportions subtly |
131| Enhancement | `enhance` | Color correction, lighting improvement, quality boost |
132| Artistic filter | `filter` | Apply a specific artistic style or filter effect |
133
134### W: Medical / fitness comparison
135
136| Action | Key | Description |
137|--------|-----|-------------|
138| Transformation comparison | `comparison` | Before/after for medical, fitness, or transformation |
139
140### X: Automotive
141
142| Action | Key | Description |
143|--------|-----|-------------|
144| Car recolor | `car_color` | Change the color of a vehicle |
145| Car wrap preview | `car_wrap` | Visualize a wrap or film on a vehicle |
146
147---
148
149## 5. Model selection guide
150
151| Model | Key | Speed | Quality | Best for |
152|-------|-----|-------|---------|----------|
153| NanoPro | `nanopro` | ~25s | Good | Default for all requests. Fast iteration. |
154| GPT Image 2 | `gpt` | ~150s | Best | When user explicitly asks for "highest quality" or "best quality". Complex edits. |
155
156**Decision rules:**
1571. **Default:** always use `nanopro` unless the user explicitly requests higher quality.
1582. **Use `gpt` when:** user says "highest quality", "best quality", "premium", or the edit requires very precise detail preservation (e.g., complex text rendering, fine inpainting).
1593. **Use `nanopro` when:** user wants fast results, is iterating on edits, or the edit is straightforward.
160
161```python
162# Default (fast)
163result = edit_image(image_path="photo.jpg", prompt="remove background", action="replace_bg")
164
165# High quality (user requested)
166result = edit_image(image_path="photo.jpg", prompt="remove background", action="replace_bg", model="gpt")
167```
168
169---
170
171## 6. Intent recognition guide
172
173Use this table to map user requests to the correct action:
174
175### General editing
176
177| User says | Action | Prompt hint |
178|-----------|--------|-------------|
179| "edit this photo", "modify this image" | `edit` | Pass user's instruction as prompt |
180| "put me on a beach", "change the scene" | `blend` | Describe the target scene |
181| "extend the image", "make it wider", "outpaint" | `extend` | Describe what to add |
182| "change just the shirt color", "edit only the sky" | `local_edit` | Specify the region and change |
183| "fewer columns", "simplify the grid", "rearrange the layout", "make it 7 columns max" | `restructure` | State the target structure explicitly (rows/columns/arrangement) |
184| "add text", "write 'Hello' on the image" | `text_render` | Specify text content and placement |
185| "show from the side", "different angle" | `multi_angle` | Describe the desired angle |
186| "before and after", "show the difference" | `before_after` | Describe the transformation |
187
188### Professional editing
189
190| User says | Action | Prompt hint |
191|-----------|--------|-------------|
192| "remove background", "change background", "换背景" | `replace_bg` | Describe the new background |
193| "upscale", "make it higher resolution", "enhance quality" | `upscale` | Optionally specify target quality |
194| "restore old photo", "fix this damaged photo", "修复老照片" | `restore` | Describe specific damage to fix |
195| "colorize", "add color to B&W photo", "上色" | `colorize` | Optionally describe expected colors |
196| "remove this person", "P掉某人" | `remove_person` | Describe which person to remove |
197
198### Retouching / beauty
199
200| User says | Action | Prompt hint |
201|-----------|--------|-------------|
202| "retouch", "smooth skin", "remove blemishes", "磨皮美白" | `retouch` | Specify retouching level |
203| "make me thinner", "slim face", "瘦脸" | `slim` | Specify areas to adjust |
204| "enhance colors", "improve lighting", "调色" | `enhance` | Describe desired look |
205| "apply filter", "make it look vintage", "滤镜" | `filter` | Describe the filter style |
206
207### Medical / fitness
208
209| User says | Action | Prompt hint |
210|-----------|--------|-------------|
211| "before and after surgery", "fitness transformation" | `comparison` | Describe the transformation context |
212
213### Automotive
214
215| User says | Action | Prompt hint |
216|-----------|--------|-------------|
217| "change car color", "make it red", "汽车改色" | `car_color` | Specify the target color and finish |
218| "car wrap", "vinyl wrap preview", "贴膜预览" | `car_wrap` | Describe wrap material and color |
219
220---
221
222## 7. Prompt engineering best practices
223
224### The prompt template system
225
226Every action has a built-in prompt template that wraps the user's instruction for optimal results. You only need to pass the user's specific intent — the template adds the technical quality instructions automatically.
227
228For example, if the user says "make the background a sunset beach":
229```python
230result = edit_image(
231 image_path="photo.jpg",
232 prompt="a beautiful sunset beach with palm trees and golden light",
233 action="replace_bg",
234)
235# The script wraps this into: "Replace the background of this image: a beautiful
236# sunset beach with palm trees and golden light. Keep the foreground subject
237# perfectly intact with clean edges. Match the lighting direction..."
238```
239
240### Key principles (from reference skills)
241
2421. **Be specific about the change** — vague prompts produce poor results:
243 - ❌ "make it better"
244 - ✅ "increase contrast, add warm golden tones, sharpen details"
245
2462. **Describe what to preserve** — especially for local edits:
247 - ❌ "change the shirt"
248 - ✅ "change the shirt color to navy blue, keep the same fabric texture and wrinkles"
249
2503. **Specify materials and finishes** — for car and product edits:
251 - ❌ "make it blue"
252 - ✅ "deep metallic blue with a glossy clear coat finish"
253
2544. **Reference real-world styles** — for filters and artistic effects:
255 - ❌ "make it artistic"
256 - ✅ "apply a warm cinematic color grade like Wes Anderson films"
257
2585. **Describe the era for restoration/colorization**:
259 - ❌ "colorize this"
260 - ✅ "colorize this 1940s family portrait with period-appropriate clothing colors"
261
2626. **For retouching, specify the level**:
263 - Light: "subtle skin smoothing, keep natural texture"
264 - Medium: "professional retouching, remove blemishes, even skin tone"
265 - Heavy: "full beauty retouching, smooth skin, brighten eyes, whiten teeth"
266
267---
268
269## 8. Usage examples by scenario
270
271### Background replacement
272
273```python
274exec(open('skills/image-edit/edit_image.py').read())
275
276# Simple background swap
277result = edit_image(
278 image_path="uploads/portrait.jpg",
279 prompt="a modern office with floor-to-ceiling windows and city skyline view",
280 action="replace_bg",
281)
282
283# Studio background
284result = edit_image(
285 image_path="uploads/product.jpg",
286 prompt="clean white studio background with soft shadow",
287 action="replace_bg",
288)
289```
290
291### Old photo restoration
292
293```python
294# Repair damaged photo
295result = edit_image(
296 image_path="uploads/old_family_photo.jpg",
297 prompt="repair all scratches, tears, and stains; restore faded colors; enhance clarity",
298 action="restore",
299)
300
301# Colorize black-and-white photo
302result = edit_image(
303 image_path="uploads/grandpa_1945.jpg",
304 prompt="colorize with historically accurate colors for 1940s era, natural skin tones, period-appropriate clothing",
305 action="colorize",
306)
307```
308
309### Portrait retouching
310
311```python
312# Professional retouching
313result = edit_image(
314 image_path="uploads/selfie.jpg",
315 prompt="professional portrait retouching: smooth skin while keeping natural texture, remove blemishes, subtle teeth whitening, brighten eyes",
316 action="retouch",
317)
318
319# Slimming
320result = edit_image(
321 image_path="uploads/photo.jpg",
322 prompt="subtle facial slimming, slightly more defined jawline, natural proportions",
323 action="slim",
324)
325```
326
327### Image enhancement
328
329```python
330# Color grading
331result = edit_image(
332 image_path="uploads/landscape.jpg",
333 prompt="cinematic color grading with warm golden tones, enhanced contrast, vibrant but natural colors",
334 action="enhance",
335)
336
337# Artistic filter
338result = edit_image(
339 image_path="uploads/photo.jpg",
340 prompt="oil painting style with visible brushstrokes, rich warm palette, impressionist feel",
341 action="filter",
342)
343```
344
345### Super-resolution upscaling
346
347```python
348result = edit_image(
349 image_path="uploads/low_res.jpg",
350 prompt="upscale to maximum quality, enhance fine details, reduce noise and compression artifacts",
351 action="upscale",
352)
353```
354
355### Person removal
356
357```python
358result = edit_image(
359 image_path="uploads/group_photo.jpg",
360 prompt="remove the person on the far right, fill with the park background seamlessly",
361 action="remove_person",
362)
363```
364
365### Outpainting (image extension)
366
367```python
368result = edit_image(
369 image_path="uploads/cropped.jpg",
370 prompt="extend the image to the left and right, continuing the mountain landscape naturally",
371 action="extend",
372 aspect_ratio="16:9",
373)
374```
375
376### Car customization
377
378```python
379# Car recolor
380result = edit_image(
381 image_path="uploads/my_car.jpg",
382 prompt="change to a deep cherry red metallic paint with glossy clear coat",
383 action="car_color",
384)
385
386# Car wrap preview
387result = edit_image(
388 image_path="uploads/my_car.jpg",
389 prompt="matte black vinyl wrap with carbon fiber accents on the hood and mirrors",
390 action="car_wrap",
391)
392```
393
394### Before/after comparison
395
396```python
397# Fitness transformation
398result = edit_image(
399 image_path="uploads/fitness_photo.jpg",
400 prompt="create a fitness transformation comparison showing a more toned and fit version",
401 action="comparison",
402)
403```
404
405### Local editing
406
407```python
408# Change specific element
409result = edit_image(
410 image_path="uploads/outfit.jpg",
411 prompt="change only the dress color from red to emerald green, keep the same fabric texture",
412 action="local_edit",
413)
414```
415
416### Text rendering
417
418```python
419result = edit_image(
420 image_path="uploads/poster_bg.jpg",
421 prompt="add the text 'SUMMER SALE' in bold white letters centered at the top, with a subtle drop shadow",
422 action="text_render",
423)
424```
425
426### High quality edit
427
428```python
429# Use GPT model for best quality
430result = edit_image(
431 image_path="uploads/important_photo.jpg",
432 prompt="professional color correction and enhancement for print publication",
433 action="enhance",
434 model="gpt",
435)
436```
437
438---
439
440## 9. Provided scripts
441
442| File | Purpose |
443|------|---------|
444| `edit_image.py` | Core script: resolve image → build prompt → submit → poll → download. Handles local files (base64) and URLs, all actions, two models. |
445| `exports.py` | Re-exports `edit_image`, `ACTIONS`, `ACTION_PROMPTS`, `MODELS` for programmatic use by other skills. |
446| `_cost_track.py` | Cost tracking helper — records per-call costs via sc-proxy headers. |
447
448---
449
450## 10. Local testing
451
452Set `FAL_KEY` env var to call fal.ai directly (bypasses sc-proxy):
453
454```bash
455# Basic edit
456FAL_KEY=your-fal-key python3 skills/image-edit/edit_image.py photo.jpg "make it brighter" enhance nanopro
457
458# Args: <image_path_or_url> [prompt] [action] [model]
459```
460
461---
462
463## 11. Troubleshooting
464
465| Problem | Fix |
466|---------|-----|
467| `File not found: ...` | Check the workspace path; the file must exist |
468| `Unsupported image format` | Use `.jpg`, `.jpeg`, `.png`, `.webp`, or `.bmp` |
469| `Image too large` | Resize to under 10 MB before uploading |
470| `image_url must be a public HTTP(S) URL` | Use `image_path` for local files, or provide a valid `https://` URL |
471| `Unknown action` | Check valid actions in §4 |
472| `HTTP 402 insufficient_credits` | Top up balance; cost is pre-charged on submit |
473| `HTTP 403 endpoint_not_allowed` | sc-proxy only allows approved fal endpoints; contact admin |
474| Edit `FAILED` upstream | Simplify prompt, ensure source image is clear, retry |
475| Job stuck `IN_PROGRESS` >10 min | Save `request_id`, retry later |
476| Poor edit quality | Try `model="gpt"` for higher quality; be more specific in prompt |
477| Layout/grid/column count won't change no matter how many times you iterate | Prefer `action="restructure"` for structural changes — its template mandates the layout change. Plain `edit` now has a precedence fallback (explicit structural instructions override composition preservation), but treat it only as a compatibility net, not the primary path |
478| Background not fully removed | Use `replace_bg` action with explicit background description |
479| Retouching looks unnatural | Add "keep natural texture" or "subtle" to prompt |
480
481---
482
483## 12. Infrastructure (reference)
484
485- Caller → `sc-proxy` → `queue.fal.run/{model}` → fal model providers
486- All requests must include `Authorization: Key fake-falai-key-12345` (proxy injects the real `FAL_KEY`)
487- Pre-charge happens at submit. Poll/result calls are free.
488- Local files are base64-encoded as data URIs — no separate upload step needed.
489- Final images live at `https://*.fal.media/...` — public CDN, no auth needed for download.
490- Cost tracking via `_cost_track.py` — records `X-Credits-Used` from sc-proxy response headers.
491
492### Model endpoints
493
494| Model | Edit endpoint |
495|-------|--------------|
496| nanopro | `fal-ai/nano-banana-pro/edit` |
497| gpt | `openai/gpt-image-2/edit` |
498
499---