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