Skip to main content
Glama
haltakov
by haltakov

generateMeme

Create meme images by providing a template ID and text, using the Imgflip API to generate visual content from text prompts.

Instructions

Generate a meme image from Imgflip using the numeric template id and text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateNumericIdYes
text0Yes
text1No

Implementation Reference

  • The handler function that implements the generateMeme tool: calls Imgflip API with template ID and texts, downloads the generated image, encodes to base64, and returns it as inline content or error.
    async ({ templateNumericId, text0, text1 }) => {
      try {
        // Prepare the Imgflip API request
        const formData = new FormData();
        formData.append("template_id", templateNumericId);
        formData.append("text0", text0);
        if (text1) formData.append("text1", text1);
        formData.append("username", process.env.IMGFLIP_USERNAME || "");
        formData.append("password", process.env.IMGFLIP_PASSWORD || "");
    
        // Send the request to the Imgflip API
        const response = await axios.post("https://api.imgflip.com/caption_image", formData, {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        });
    
        // Get the image URL from the response
        const imageUrl = response.data.data.url;
    
        // Download the image
        const imageResponse = await axios.get(imageUrl, { responseType: "arraybuffer" });
        const imageDataBase64 = imageResponse.data.toString("base64");
    
        // Return the image as a base64 encoded string
        return {
          content: [{ type: "image", data: imageDataBase64, mimeType: "image/png" }],
        };
      } catch (error) {
        // Return an error message
        return {
          content: [
            {
              type: "text",
              text: "Failed to generate meme image",
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema using Zod: templateNumericId (string), text0 (string), text1 (optional string).
      templateNumericId: z.string(),
      text0: z.string(),
      text1: z.string().optional(),
    },
  • src/index.ts:15-64 (registration)
    Registration of the generateMeme tool using server.tool() with name, description, input schema, and handler function.
    server.tool(
      "generateMeme",
      "Generate a meme image from Imgflip using the numeric template id and text",
      {
        templateNumericId: z.string(),
        text0: z.string(),
        text1: z.string().optional(),
      },
      async ({ templateNumericId, text0, text1 }) => {
        try {
          // Prepare the Imgflip API request
          const formData = new FormData();
          formData.append("template_id", templateNumericId);
          formData.append("text0", text0);
          if (text1) formData.append("text1", text1);
          formData.append("username", process.env.IMGFLIP_USERNAME || "");
          formData.append("password", process.env.IMGFLIP_PASSWORD || "");
    
          // Send the request to the Imgflip API
          const response = await axios.post("https://api.imgflip.com/caption_image", formData, {
            headers: {
              "Content-Type": "multipart/form-data",
            },
          });
    
          // Get the image URL from the response
          const imageUrl = response.data.data.url;
    
          // Download the image
          const imageResponse = await axios.get(imageUrl, { responseType: "arraybuffer" });
          const imageDataBase64 = imageResponse.data.toString("base64");
    
          // Return the image as a base64 encoded string
          return {
            content: [{ type: "image", data: imageDataBase64, mimeType: "image/png" }],
          };
        } catch (error) {
          // Return an error message
          return {
            content: [
              {
                type: "text",
                text: "Failed to generate meme image",
              },
            ],
            isError: true,
          };
        }
      }
    );
Install Server

Other 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/haltakov/meme-mcp'

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