Skip to main content
Glama

create_sprite_atlas

Combine multiple images into a single sprite atlas or spritesheet for game development and asset management.

Instructions

Combine multiple images into a sprite atlas/spritesheet.

Args: images_base64: List of base64 encoded images columns: Number of columns in the atlas padding: Padding between sprites in pixels save_to_file: Whether to save atlas to disk filename: Custom filename for the atlas Returns: JSON with the combined atlas as base64

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
images_base64Yes
columnsNo
paddingNo
save_to_fileNo
filenameNo

Implementation Reference

  • The primary handler and registration for the create_sprite_atlas tool via @mcp.tool() decorator. Processes input base64 images, delegates atlas creation to create_spritesheet helper, handles file saving, and returns JSON with base64 atlas.
    @mcp.tool() async def create_sprite_atlas( images_base64: List[str], columns: int = 4, padding: int = 0, save_to_file: bool = False, filename: Optional[str] = None ) -> str: """Combine multiple images into a sprite atlas/spritesheet. Args: images_base64: List of base64 encoded images columns: Number of columns in the atlas padding: Padding between sprites in pixels save_to_file: Whether to save atlas to disk filename: Custom filename for the atlas Returns: JSON with the combined atlas as base64 """ import base64 images = [base64.b64decode(img) for img in images_base64] atlas_bytes = create_spritesheet(images, columns=columns, padding=padding) result = { "success": True, "image_base64": image_to_base64(atlas_bytes), "sprite_count": len(images), "columns": columns } if save_to_file: output_dir = ensure_directory(OUTPUT_DIR / "atlases") fname = filename or generate_filename(prefix="atlas") file_path = output_dir / fname file_path.write_bytes(atlas_bytes) result["file_path"] = str(file_path) return json.dumps(result, indent=2)
  • Supporting utility function that implements the core sprite atlas creation logic using PIL: loads images, computes grid layout, pastes into transparent canvas, and returns PNG bytes.
    def create_spritesheet( images: List[bytes], columns: int = 4, padding: int = 0 ) -> bytes: """Create a spritesheet from multiple images.""" if not images: raise ValueError("No images provided") # Load all images pil_images = [Image.open(BytesIO(img)) for img in images] # Get dimensions (assume all same size) sprite_width = pil_images[0].width sprite_height = pil_images[0].height # Calculate sheet dimensions rows = (len(pil_images) + columns - 1) // columns sheet_width = columns * sprite_width + (columns - 1) * padding sheet_height = rows * sprite_height + (rows - 1) * padding # Create spritesheet sheet = Image.new("RGBA", (sheet_width, sheet_height), (0, 0, 0, 0)) for i, img in enumerate(pil_images): row = i // columns col = i % columns x = col * (sprite_width + padding) y = row * (sprite_height + padding) sheet.paste(img, (x, y)) buffer = BytesIO() sheet.save(buffer, format="PNG") return buffer.getvalue()

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/tuannguyen14/ComfyAI-MCP-GameAssets'

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