Skip to main content
Glama
yunwoong7
by yunwoong7

image_conditioning

Generate images matching the layout and composition of a reference image using text prompts and control modes. Specify attributes to include or exclude for precise output customization.

Instructions

Generate an image that follows the layout and composition of a reference image.

Args:
    image_path: File path of the reference image
    prompt: Text describing the image to be generated
    negative_prompt: Text specifying attributes to exclude from generation
    control_mode: Control mode (CANNY_EDGE, etc.)
    height: Output image height (pixels)
    width: Output image width (pixels)
    cfg_scale: Prompt matching degree (1-20)
    
Returns:
    Dict: Dictionary containing the file path of the generated image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cfg_scaleNo
control_modeNoCANNY_EDGE
heightNo
image_pathYes
negative_promptNo
promptYes
widthNo

Implementation Reference

  • The primary handler function implementing the image_conditioning tool. It processes a reference image, generates a conditioned image using Bedrock API, saves it, and returns the path.
    async def image_conditioning(
            image_path: str,
            prompt: str,
            negative_prompt: str = "",
            control_mode: str = "CANNY_EDGE",
            height: int = 512,
            width: int = 512,
            cfg_scale: float = 8.0,
            output_path: str = None,
    ) -> Dict[str, Any]:
        """
        Generate an image that follows the layout and composition of a reference image.
        
        Args:
            image_path: File path of the reference image
            prompt: Text describing the image to be generated
            negative_prompt: Text specifying attributes to exclude from generation
            control_mode: Control mode (CANNY_EDGE, etc.)
            height: Output image height (pixels)
            width: Output image width (pixels)
            cfg_scale: Prompt matching degree (1-20)
            output_path: Absolute path to save the image
            
        Returns:
            Dict: Dictionary containing the file path of the generated image
        """
        try:
            # Read image file and encode to base64
            with open(image_path, "rb") as image_file:
                input_image = base64.b64encode(image_file.read()).decode('utf8')
    
            body = json.dumps({
                "taskType": "TEXT_IMAGE",
                "textToImageParams": {
                    "text": prompt,
                    "negativeText": negative_prompt,
                    "conditionImage": input_image,
                    "controlMode": control_mode
                },
                "imageGenerationConfig": {
                    "numberOfImages": 1,
                    "height": height,
                    "width": width,
                    "cfgScale": cfg_scale
                }
            })
    
            # Generate image
            image_bytes = generate_image(body)
    
            # Save image
            image_info = save_image(image_bytes, output_path=output_path)
    
            # Generate result
            result = {
                "image_path": image_info["image_path"],
                "message": f"Image conditioning completed successfully. Saved location: {image_info['image_path']}"
            }
    
            return result
    
        except Exception as e:
            raise McpError(f"Error occurred while image conditioning: {str(e)}")
  • Registration point for the image_conditioning tool in the MCP server (currently commented out).
    # mcp.add_tool(image_conditioning)
  • Import statement bringing the image_conditioning handler into the server module.
    from .tools.image_conditioning import image_conditioning

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yunwoong7/aws-nova-canvas-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server