Readme
Nano Banana 2 Transparent
Generate images with real alpha transparency using Nano Banana 2 (Google Gemini 3.1 Flash Image).
Unlike background removal tools that process after the fact, this model uses triangulation matting — generating the same subject on white and black backgrounds, then computing mathematically accurate per-pixel alpha values. This produces clean edges, proper semi-transparency, and correct color recovery that background removers can’t match.
How it works
- Your prompt is sent to Nano Banana 2 with a white background
- The white result is edited to a black background (constrained edit, preserving the foreground exactly)
- A triangulation matte computes the true alpha channel from the white/black pair:
alpha = 1 - (white_pixel - black_pixel) / 255- Foreground color is recovered via weighted unpremultiply
- Output is a PNG with proper RGBA transparency
Parameters
All Nano Banana 2 parameters are supported:
| Parameter | Description |
|---|---|
prompt |
Text description of the image to generate |
image_input |
Optional input image for editing (result will have transparency) |
aspect_ratio |
1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1, match_input_image |
resolution |
512px, 1K, 2K, 4K |
google_search |
Ground generation in real-time web data |
image_search |
Use Google Image Search for visual context |
replicate_api_token |
Your Replicate API token (required — the model calls Nano Banana 2 internally) |
Output
Always returns a PNG with alpha channel (RGBA). The output format is always PNG regardless of settings, since transparency requires it.
Use cases
- Game assets and sprites with clean edges
- UI elements and icons with proper transparency
- Product photos on transparent backgrounds
- Stickers and overlays
- Design assets ready for compositing
Note on billing
This model calls Nano Banana 2 twice per run (white + black background). You are billed for: - This model’s CPU compute time (minimal — just pixel math) - Two Nano Banana 2 runs (the main cost)
Your replicate_api_token is handled securely and never logged.