transform_image_from_encoded
Modify images using text prompts by converting encoded images into transformed versions with Google's Gemini model. Saves the output locally for quick access.
Instructions
Transform an existing image based on the given text prompt using Google's Gemini model.
Args:
encoded_image: Base64 encoded image data with header. Must be in format:
"data:image/[format];base64,[data]"
Where [format] can be: png, jpeg, jpg, gif, webp, etc.
prompt: Text prompt describing the desired transformation or modifications
Returns:
Path to the transformed image file saved on the server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| encoded_image | Yes | ||
| prompt | Yes |
Implementation Reference
- src/gemini_image_mcp/server.py:272-300 (handler)Main handler function for the 'transform_image_from_encoded' tool. Decorated with @mcp.tool() for automatic registration and schema inference from signature/docstring. Loads base64 image, translates prompt, transforms via Gemini API.@mcp.tool() async def transform_image_from_encoded(encoded_image: str, prompt: str) -> str: """Transform an existing image based on the given text prompt using Google's Gemini model. Args: encoded_image: Base64 encoded image data with header. Must be in format: "data:image/[format];base64,[data]" Where [format] can be: png, jpeg, jpg, gif, webp, etc. prompt: Text prompt describing the desired transformation or modifications Returns: Path to the transformed image file saved on the server """ try: logger.info(f"Processing transform_image_from_encoded request with prompt: {prompt}") # Load and validate the image source_image, _ = await load_image_from_base64(encoded_image) # Translate the prompt to English translated_prompt = await translate_prompt(prompt) # Process the transformation return await process_image_transform(source_image, translated_prompt, prompt) except Exception as e: error_msg = f"Error transforming image: {str(e)}" logger.error(error_msg) return error_msg