In-App Asset Generation & Processing
This skill provides best practices and processing scripts for generating high-quality 2D sprites, icons, backgrounds, and UI elements using AI image generation, then preparing them for use in web or mobile apps.
Prompt Engineering Best Practices
When using an image generation tool (Imagen, DALL-E, etc.) to create app or game components, follow these rules for consistency and usability:
- Format & Perspective: Always explicitly ask for a "clean, simple 2D flat vector graphic". Do not allow the model to generate 3D renders, gradients, or complex shading unless specifically requested.
- Style Transfer via Reference Images: Whenever possible, pass a screenshot of your app's UI as a reference image. State in the prompt: "Using the provided screenshot as a direct style, color, and aesthetic reference..." This is the most effective way to guarantee brand alignment.
- Encode Your Design System: Explicitly include your app's design mandates in the prompt. Reference your outline style, fill patterns, and visual language (e.g., "thick dark outlines, flat pastel fills, rounded corners").
- Use Exact Hex Codes: Do not use vague color names like "red" or "blue". Extract exact hex codes from your app's CSS or design tokens and force the prompt to use them (e.g.,
Primary #3B82F6, Accent #F59E0B).
- Background Isolation: To ensure the processing script can strip the background for transparent PNGs, always end your prompt with: "Solid white background. Do not add any shadows dropping onto the background canvas."
Example: Applying a Design System
If your app uses a Neo-Brutalist style:
"2D flat vector graphic of a treasure chest. Thick navy blue (#1D3557) outlines,
solid Gold (#F4A261) fill, neo-brutalist style. Solid white background."
If your app uses a soft/rounded style:
"2D flat vector graphic of a treasure chest. Thin rounded outlines (#374151),
soft gradient fills in sky blue (#7DD3FC) to white, modern minimal style.
Solid white background."
The key is extracting your design tokens and embedding them directly in every prompt.
Creating Consistent Icon Sets
When building an entire set of UI icons or game sprites, they must look like they belong to the same visual family.
- Batch Generation Strategy: Generate icons as a single tiled atlas or "sprite sheet" in one API request (e.g., "generate a 2x2 grid containing a coin, a sword, a shield, and a potion, all in the exact same style"). Then slice them programmatically with the included script.
- Anchor with Reference Images: Every image generation request must receive the exact same reference image. This forces the model to continuously reference the same styling rules.
- Rigid Prompt Templates: Develop a rigid prompt template and only swap out the subject:
"Using the attached UI reference image, generate a clean 2D flat vector
graphic of [SUBJECT]. [OUTLINE_STYLE], [FILL_STYLE], [DESIGN_SYSTEM].
Solid white background."
- Validate Against Design Tokens: Check generated outputs against your app's CSS tokens before finalizing. If a generated asset uses a slightly different color than your design system, adjust and regenerate.
Processing Assets
AI image generators typically output JPEG or WebP files with baked-in backgrounds. To use these as components, strip the background and convert to RGBA PNGs.
Background Removal
Script Path: <path-to-skill>/scripts/process_asset.py
python <path-to-skill>/scripts/process_asset.py \
--input "/path/to/generated_image.png" \
--out_dir "./public/game_assets" \
--name "coin" \
--crop
Arguments:
--input (Required): Path to the raw generated image.
--out_dir (Required): Destination directory for the transparent PNG.
--name (Required): Output filename without .png extension.
--crop (Optional): Auto-crop transparent padding around the asset.
--threshold (Optional): White detection threshold (0-255). Default 240. Lower values are more aggressive at removing near-white pixels. Raise to 250 if the asset has light-colored areas being incorrectly removed.
Sprite Sheet Slicing
Script Path: <path-to-skill>/scripts/slice_sprites.py
python <path-to-skill>/scripts/slice_sprites.py \
--input "/path/to/spritesheet.png" \
--out_dir "./public/game_assets/icons" \
--prefix "item" \
--rows 2 --cols 3
Arguments:
--input (Required): Path to the sprite sheet image.
--out_dir (Required): Destination directory for sliced images.
--prefix (Required): Filename prefix (outputs prefix_0.png, prefix_1.png, ...).
--rows (Required): Number of rows in the grid.
--cols (Required): Number of columns in the grid.
--col_major (Optional): Iterate columns first instead of rows.
Workflow Example
- Identify the need for a new "Coin" icon.
- Look up your design tokens — find the gold hex code (e.g.,
#F4A261).
- Generate with your image tool: "2D flat vector graphic of a coin. [your outline style], solid Gold (#F4A261) fill. Solid white background."
- Process:
python <path-to-skill>/scripts/process_asset.py --input ./artifact.png --out_dir ./public/game_assets --name coin --crop
- Wire
/game_assets/coin.png into your component.
1---2name: in-app-asset-generator3description: Generate and process 2D game assets, sprites, icons, UI graphics, and custom imagery for in-app experiences. Covers prompt engineering for consistent vector art, background removal, sprite sheet slicing, and design system alignment. Use when creating game visuals, icon packs, animations, or any custom in-app imagery.4---56# In-App Asset Generation & Processing78This skill provides best practices and processing scripts for generating high-quality 2D sprites, icons, backgrounds, and UI elements using AI image generation, then preparing them for use in web or mobile apps.910## Prompt Engineering Best Practices1112When using an image generation tool (Imagen, DALL-E, etc.) to create app or game components, follow these rules for consistency and usability:13141. **Format & Perspective**: Always explicitly ask for a *"clean, simple 2D flat vector graphic"*. Do not allow the model to generate 3D renders, gradients, or complex shading unless specifically requested.152. **Style Transfer via Reference Images**: Whenever possible, pass a screenshot of your app's UI as a reference image. State in the prompt: *"Using the provided screenshot as a direct style, color, and aesthetic reference..."* This is the most effective way to guarantee brand alignment.163. **Encode Your Design System**: Explicitly include your app's design mandates in the prompt. Reference your outline style, fill patterns, and visual language (e.g., *"thick dark outlines, flat pastel fills, rounded corners"*).174. **Use Exact Hex Codes**: Do not use vague color names like "red" or "blue". Extract exact hex codes from your app's CSS or design tokens and force the prompt to use them (e.g., `Primary #3B82F6`, `Accent #F59E0B`).185. **Background Isolation**: To ensure the processing script can strip the background for transparent PNGs, always end your prompt with: *"Solid white background. Do not add any shadows dropping onto the background canvas."*1920### Example: Applying a Design System2122If your app uses a Neo-Brutalist style:23```24"2D flat vector graphic of a treasure chest. Thick navy blue (#1D3557) outlines,25solid Gold (#F4A261) fill, neo-brutalist style. Solid white background."26```2728If your app uses a soft/rounded style:29```30"2D flat vector graphic of a treasure chest. Thin rounded outlines (#374151),31soft gradient fills in sky blue (#7DD3FC) to white, modern minimal style.32Solid white background."33```3435The key is extracting your design tokens and embedding them directly in every prompt.3637## Creating Consistent Icon Sets3839When building an entire set of UI icons or game sprites, they must look like they belong to the same visual family.40411. **Batch Generation Strategy**: Generate icons as a single tiled atlas or "sprite sheet" in one API request (e.g., *"generate a 2x2 grid containing a coin, a sword, a shield, and a potion, all in the exact same style"*). Then slice them programmatically with the included script.422. **Anchor with Reference Images**: Every image generation request *must* receive the exact same reference image. This forces the model to continuously reference the same styling rules.433. **Rigid Prompt Templates**: Develop a rigid prompt template and only swap out the subject:44 ```45 "Using the attached UI reference image, generate a clean 2D flat vector46 graphic of [SUBJECT]. [OUTLINE_STYLE], [FILL_STYLE], [DESIGN_SYSTEM].47 Solid white background."48 ```494. **Validate Against Design Tokens**: Check generated outputs against your app's CSS tokens before finalizing. If a generated asset uses a slightly different color than your design system, adjust and regenerate.5051## Processing Assets5253AI image generators typically output JPEG or WebP files with baked-in backgrounds. To use these as components, strip the background and convert to RGBA PNGs.5455### Background Removal5657**Script Path:** `<path-to-skill>/scripts/process_asset.py`5859```bash60python <path-to-skill>/scripts/process_asset.py \61 --input "/path/to/generated_image.png" \62 --out_dir "./public/game_assets" \63 --name "coin" \64 --crop65```6667**Arguments:**68* `--input` (Required): Path to the raw generated image.69* `--out_dir` (Required): Destination directory for the transparent PNG.70* `--name` (Required): Output filename without `.png` extension.71* `--crop` (Optional): Auto-crop transparent padding around the asset.72* `--threshold` (Optional): White detection threshold (0-255). Default `240`. Lower values are more aggressive at removing near-white pixels. Raise to `250` if the asset has light-colored areas being incorrectly removed.7374### Sprite Sheet Slicing7576**Script Path:** `<path-to-skill>/scripts/slice_sprites.py`7778```bash79python <path-to-skill>/scripts/slice_sprites.py \80 --input "/path/to/spritesheet.png" \81 --out_dir "./public/game_assets/icons" \82 --prefix "item" \83 --rows 2 --cols 384```8586**Arguments:**87* `--input` (Required): Path to the sprite sheet image.88* `--out_dir` (Required): Destination directory for sliced images.89* `--prefix` (Required): Filename prefix (outputs `prefix_0.png`, `prefix_1.png`, ...).90* `--rows` (Required): Number of rows in the grid.91* `--cols` (Required): Number of columns in the grid.92* `--col_major` (Optional): Iterate columns first instead of rows.9394## Workflow Example95961. Identify the need for a new "Coin" icon.972. Look up your design tokens — find the gold hex code (e.g., `#F4A261`).983. Generate with your image tool: *"2D flat vector graphic of a coin. [your outline style], solid Gold (#F4A261) fill. Solid white background."*994. Process: `python <path-to-skill>/scripts/process_asset.py --input ./artifact.png --out_dir ./public/game_assets --name coin --crop`1005. Wire `/game_assets/coin.png` into your component.