Skip to main content
Glama

generate_image_imagen

Create photorealistic images for professional branding using Imagen 4 with high-resolution outputs based on text descriptions.

Instructions

Generate images using Imagen 4. Best for photorealistic quality, high-resolution outputs, and professional branding. Paid service.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesDescription of the image to generate (in English, max 480 tokens)
numberOfImagesNoNumber of images to generate (1-4, default: 1)

Implementation Reference

  • Executes the 'generate_image_imagen' tool by calling the Imagen 4 REST API, handling the response, saving images to disk, and returning text and image content.
    if (name === "generate_image_imagen") { const { prompt, numberOfImages = 1 } = args; // REST API를 사용하여 Imagen 4 호출 const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict`, { method: "POST", headers: { "x-goog-api-key": apiKey, "Content-Type": "application/json", }, body: JSON.stringify({ instances: [{ prompt: prompt }], parameters: { sampleCount: numberOfImages, }, }), } ); if (!response.ok) { const errorText = await response.text(); throw new Error(`Imagen API error: ${response.status} - ${errorText}`); } const result = await response.json(); // predictions 배열 확인 (실제 API 응답 구조) if (!result.predictions || result.predictions.length === 0) { throw new Error(`No images were generated. Response: ${JSON.stringify(result)}`); } // 이미지 저장 const outputDir = join(__dirname, "generated_images"); await mkdir(outputDir, { recursive: true }); const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); const savedPaths = []; for (let i = 0; i < result.predictions.length; i++) { const img = result.predictions[i]; const filename = `imagen_${timestamp}_${i + 1}.png`; const filepath = join(outputDir, filename); // bytesBase64Encoded 필드 사용 const buffer = Buffer.from(img.bytesBase64Encoded, "base64"); await writeFile(filepath, buffer); savedPaths.push(filepath); } return { content: [ { type: "text", text: `[Imagen 4]\n\nGenerated ${result.predictions.length} image(s) for: "${prompt}"\n\nSaved to:\n${savedPaths.map(p => `- ${p}`).join("\n")}\n\nNote: All images include SynthID watermark for authenticity.`, }, ...result.predictions.map((img) => ({ type: "image", data: img.bytesBase64Encoded, mimeType: img.mimeType || "image/png", })), ], }; }
  • index.js:119-142 (registration)
    Registers the 'generate_image_imagen' tool in the ListTools response, defining its name, description, and input schema.
    { name: "generate_image_imagen", description: "Generate images using Imagen 4. Best for photorealistic quality, high-resolution outputs, and professional branding. Paid service.", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "Description of the image to generate (in English, max 480 tokens)", }, numberOfImages: { type: "number", description: "Number of images to generate (1-4, default: 1)", default: 1, minimum: 1, maximum: 4, }, }, required: ["prompt"], }, },
  • Defines the input schema for the 'generate_image_imagen' tool, specifying prompt and optional numberOfImages parameters.
    inputSchema: { type: "object", properties: { prompt: { type: "string", description: "Description of the image to generate (in English, max 480 tokens)", }, numberOfImages: { type: "number", description: "Number of images to generate (1-4, default: 1)", default: 1, minimum: 1, maximum: 4, }, }, required: ["prompt"], },

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/Yoon-jongho/claude-to-gemini'

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