Generate images using Google Gemini API. Use when the user asks to create, generate, or produce images, illustrations, sprites, backgrounds, or any visual assets for the game.
Generate images using Google's Gemini API with Imagen 3 model.
Set your API key as environment variable:
export GEMINI_API_KEY="your-api-key"
Or create a .env file in project root (add to .gitignore):
GEMINI_API_KEY=your-api-key
Use this curl command to generate images:
curl -s "https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-002:predict?key=${GEMINI_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"instances": [{"prompt": "YOUR_PROMPT_HERE"}],
"parameters": {"sampleCount": 1, "aspectRatio": "16:9"}
}' | jq -r '.predictions[0].bytesBase64Encoded' | base64 -d > output.png
| Parameter | Options | Description |
|---|---|---|
sampleCount | 1-4 | Number of images to generate |
aspectRatio | 1:1, 3:4, 4:3, 9:16, 16:9 | Image aspect ratio |
When user requests an image:
Craft the prompt based on HorseHeave art style:
Generate the image:
curl -s "https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-002:predict?key=${GEMINI_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"instances": [{"prompt": "A cartoon style horse ranch barn with red roof, white fences, warm sunset colors, game asset, bright and cheerful, no text"}],
"parameters": {"sampleCount": 1, "aspectRatio": "16:9"}
}' | jq -r '.predictions[0].bytesBase64Encoded' | base64 -d > src/assets/images/generated_image.png
Save to appropriate location:
src/assets/images/ui/src/assets/images/horses/src/assets/images/buildings/src/assets/images/environment/A cute cartoon horse, chestnut brown color, standing pose, side view, game sprite, transparent background, warm friendly style, vector art, clean lines
Cartoon style wooden horse stable building, red and brown colors, farm aesthetic, isometric view, game asset, bright daylight, no text, clean design
Cartoon game UI button, golden frame, green center, glossy, rounded rectangle, game asset, transparent background, no text
Peaceful horse ranch landscape, rolling green hills, blue sky with fluffy clouds, wooden fences, cartoon illustration style, warm colors, 16:9 aspect ratio, no text
echo $GEMINI_API_KEYInstall jq:
brew install jqapt install jqIf Imagen is not available, use Gemini 2.0 Flash for image generation:
curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${GEMINI_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Generate an image: YOUR_PROMPT_HERE"}]}],
"generationConfig": {"responseModalities": ["IMAGE", "TEXT"]}
}' | jq -r '.candidates[0].content.parts[0].inlineData.data' | base64 -d > output.png