xiaohongshu
xiaohongshu
gemini-image
Invoke Google Gemini for image generation and understanding using the Python google-genai SDK. Supports gemini-3-pro-image-preview (generation + understanding), gemini-2.5-flash-image (fast generation), and vision models for analysis.
Full skill instructions
Invoke Google Gemini models for image generation, image understanding, and visual analysis using the Python google-genai SDK.
| Model ID | Description | Best For | Output Format |
|---|---|---|---|
gemini-3-pro-image-preview | Best image generation + understanding | High-quality image gen, complex visual analysis | JPEG |
gemini-2.5-flash-image | Fast image generation | Quick image creation | PNG |
gemini-3-pro-preview | Multimodal understanding | Image analysis without generation | N/A |
gemini-2.5-flash | Fast vision | Quick image analysis | N/A |
API Key: ${GEMINI_API_KEY}
python -c "
from google import genai
from google.genai import types
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
response = client.models.generate_content(
model='gemini-3-pro-image-preview', # Returns JPEG | Use gemini-2.5-flash-image for PNG
contents='Generate an image of a sunset over mountains',
config=types.GenerateContentConfig(
response_modalities=['IMAGE', 'TEXT']
)
)
# Map mime types to file extensions
mime_to_ext = {'image/png': '.png', 'image/jpeg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp'}
# Save generated image
if response.candidates and response.candidates[0].content:
for part in response.candidates[0].content.parts:
if hasattr(part, 'inline_data') and part.inline_data:
ext = mime_to_ext.get(part.inline_data.mime_type, '.png')
filename = f'output{ext}'
# Data is already raw bytes - no base64 decode needed
with open(filename, 'wb') as f:
f.write(part.inline_data.data)
print(f'Image saved to {filename} ({part.inline_data.mime_type})')
elif hasattr(part, 'text'):
print(part.text)
"
python -c "
from google import genai
from google.genai import types
import base64
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
# Read image file - must be base64 encoded for INPUT
with open('IMAGE_PATH', 'rb') as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
response = client.models.generate_content(
model='gemini-3-pro-preview',
contents=[
types.Content(parts=[
types.Part(text='Describe this image in detail'),
types.Part(inline_data=types.Blob(mime_type='image/png', data=image_data))
])
]
)
print(response.text)
"
python -c "
from google import genai
from google.genai import types
import urllib.request
import base64
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
# Fetch image from URL - must be base64 encoded for INPUT
url = 'IMAGE_URL_HERE'
with urllib.request.urlopen(url) as response:
image_data = base64.b64encode(response.read()).decode('utf-8')
response = client.models.generate_content(
model='gemini-3-pro-preview',
contents=[
types.Content(parts=[
types.Part(text='What is in this image?'),
types.Part(inline_data=types.Blob(mime_type='image/jpeg', data=image_data))
])
]
)
print(response.text)
"
When this skill is invoked:
Determine the task type:
Select the appropriate model:
gemini-3-pro-image-preview (JPEG) or gemini-2.5-flash-image (PNG)gemini-3-pro-preview or gemini-2.5-flashPrepare the input:
Execute and handle output:
python -c "
from google import genai
from google.genai import types
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
response = client.models.generate_content(
model='gemini-3-pro-image-preview',
contents='Create a professional product photo of a sleek wireless headphone on a white background, studio lighting',
config=types.GenerateContentConfig(
response_modalities=['IMAGE', 'TEXT']
)
)
mime_to_ext = {'image/png': '.png', 'image/jpeg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp'}
if response.candidates and response.candidates[0].content:
for part in response.candidates[0].content.parts:
if hasattr(part, 'inline_data') and part.inline_data:
ext = mime_to_ext.get(part.inline_data.mime_type, '.png')
with open(f'headphone{ext}', 'wb') as f:
f.write(part.inline_data.data)
print(f'Image saved to headphone{ext}')
"
python -c "
from google import genai
from google.genai import types
import base64
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
with open('screenshot.png', 'rb') as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
response = client.models.generate_content(
model='gemini-3-pro-preview',
contents=[
types.Content(parts=[
types.Part(text='Analyze this UI screenshot. Identify any usability issues and suggest improvements.'),
types.Part(inline_data=types.Blob(mime_type='image/png', data=image_data))
])
]
)
print(response.text)
"
python -c "
from google import genai
from google.genai import types
import base64
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
with open('document.png', 'rb') as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
response = client.models.generate_content(
model='gemini-3-pro-preview',
contents=[
types.Content(parts=[
types.Part(text='Extract all text from this image. Preserve formatting where possible.'),
types.Part(inline_data=types.Blob(mime_type='image/png', data=image_data))
])
]
)
print(response.text)
"
python -c "
from google import genai
from google.genai import types
import base64
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
with open('image1.png', 'rb') as f:
img1_data = base64.b64encode(f.read()).decode('utf-8')
with open('image2.png', 'rb') as f:
img2_data = base64.b64encode(f.read()).decode('utf-8')
response = client.models.generate_content(
model='gemini-3-pro-preview',
contents=[
types.Content(parts=[
types.Part(text='Compare these two images. What are the key differences?'),
types.Part(inline_data=types.Blob(mime_type='image/png', data=img1_data)),
types.Part(inline_data=types.Blob(mime_type='image/png', data=img2_data))
])
]
)
print(response.text)
"
When generating images, you can customize:
config=types.GenerateContentConfig(
response_modalities=['IMAGE', 'TEXT'], # Request both image and description
temperature=1.0, # Higher = more creative
# Additional parameters may be model-specific
)
Input (for understanding):
image/png)image/jpeg)image/gif)image/webp)Output (from generation):
image/png)part.inline_data.data (NOT base64 encoded)part.inline_data.mime_type to determine the actual format returnedCommon errors and solutions:
response_modalities=['IMAGE', 'TEXT'] in configxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience