Skip to main content
Glama

convert

Transform images into ASCII art from URLs or base64 sources. Generate customizable text artwork with size tiers (16/32/64), brightness inversion, and structured storage options.

Instructions

Convert an image (URL or base64) to ASCII art at a specific size tier.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlNoImage URL to convert
base64NoBase64-encoded image data
sizeNoArt size tier: "16" (simple, default), "32" (medium), "64" (detailed)16
invertNoInvert brightness
contrastNoApply auto-contrast
gammaNoGamma correction
saveNoSave the converted art to the store

Implementation Reference

  • The main convertImage function that converts image buffers to ASCII art. Handles resizing, grayscale conversion, contrast normalization, gamma correction, and brightness inversion. Uses sharp library for image processing and maps pixel brightness to ASCII characters using a ramp.
    export async function convertImage(
      input: Buffer,
      opts: ConvertOptions = {},
    ): Promise<string> {
      const maxW = opts.width ?? 64;
      const maxH = opts.height ?? 32;
      const invert = opts.invert ?? false;
      const contrast = opts.contrast ?? true;
      const gamma = opts.gamma ?? 1.0;
    
      const instance = sharp(input);
      const metadata = await instance.metadata();
      const origW = metadata.width ?? maxW;
      const origH = metadata.height ?? maxH;
      const aspect = origH / origW;
    
      let newW = maxW;
      let newH = Math.floor(newW * aspect * 0.5);
    
      if (newH > maxH) {
        newH = maxH;
        newW = Math.floor(newH / aspect * 2);
      }
    
      newW = Math.max(newW, 1);
      newH = Math.max(newH, 1);
    
      let pipeline = instance.flatten({ background: '#ffffff' }).grayscale();
    
      if (contrast) {
        pipeline = pipeline.normalise();
      }
    
      const { data } = await pipeline
        .resize(newW, newH, { fit: 'fill', kernel: 'lanczos3' })
        .raw()
        .toBuffer({ resolveWithObject: true });
    
      const lines: string[] = [];
      for (let y = 0; y < newH; y++) {
        let row = '';
        for (let x = 0; x < newW; x++) {
          let brightness = data[y * newW + x];
          if (invert) {
            brightness = 255 - brightness;
          }
          const normalized = Math.pow(brightness / 255, gamma);
          const idx = Math.min(Math.floor(normalized * RAMP_LEN), RAMP_LEN);
          row += ASCII_RAMP[idx];
        }
        lines.push(row.trimEnd());
      }
    
      while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
        lines.pop();
      }
    
      return lines.join('\n');
    }
  • src/mcp.ts:180-232 (registration)
    Registration of the 'convert' tool with the MCP server. Defines the tool name, description, input schema (url, base64, size, invert, contrast, gamma, save), and the handler function that orchestrates image resolution and conversion.
    server.tool(
      'convert',
      'Convert an image (URL or base64) to ASCII art at a specific size tier.',
      {
        url: z.string().url().optional().describe('Image URL to convert'),
        base64: z.string().optional().describe('Base64-encoded image data'),
        size: sizeSchema,
        invert: z.boolean().default(false).describe('Invert brightness'),
        contrast: z.boolean().default(true).describe('Apply auto-contrast'),
        gamma: z.number().min(0.1).max(5).default(1.0).describe('Gamma correction'),
        save: z.object({
          name: z.string().max(MAX_NAME_LENGTH),
          description: z.string().max(MAX_DESCRIPTION_LENGTH).optional(),
          category: z.string().max(MAX_NAME_LENGTH),
          tags: z.array(z.string().max(MAX_TAG_LENGTH)).max(MAX_TAGS),
        }).optional().describe('Save the converted art to the store'),
      },
      async ({ url, base64, size, invert, contrast, gamma, save }) => {
        if (!url && !base64) {
          return { content: [{ type: 'text', text: 'Error: provide either "url" or "base64"' }], isError: true };
        }
        try {
          const s = Number(size) as ArtSize;
          const { width: maxW, height: maxH } = SIZE_LIMITS[s];
          const source = (url ?? base64)!;
          const buf = await resolveImageInput(source);
          const art = await convertImage(buf, { width: maxW, height: maxH, invert, contrast, gamma });
    
          const lines = art.split('\n');
          const artWidth = Math.max(...lines.map((l) => l.length), 0);
          const artHeight = lines.length;
    
          let savedMsg = '';
          if (save) {
            const entry = await addArt({
              name: save.name,
              description: save.description,
              category: save.category.toLowerCase(),
              tags: save.tags,
              size: s,
              art,
            });
            savedMsg = `\n\nSaved as "${entry.id}" [${entry.size}w ${entry.width}x${entry.height}]`;
          }
    
          const text = `--- ${s}w [${artWidth}x${artHeight}] ---\n${art}${savedMsg}`;
          return { content: [{ type: 'text', text }] };
        } catch (err: unknown) {
          const e = err as { message?: string };
          return { content: [{ type: 'text', text: `Error: ${e.message ?? 'Conversion failed'}` }], isError: true };
        }
      }
    );
  • Input schema definition for the convert tool using Zod. Defines validation rules for url (optional URL string), base64 (optional string), size (enum '16'|'32'|'64'), invert/contrast (booleans), gamma (number 0.1-5), and optional save object with name, description, category, and tags.
    {
      url: z.string().url().optional().describe('Image URL to convert'),
      base64: z.string().optional().describe('Base64-encoded image data'),
      size: sizeSchema,
      invert: z.boolean().default(false).describe('Invert brightness'),
      contrast: z.boolean().default(true).describe('Apply auto-contrast'),
      gamma: z.number().min(0.1).max(5).default(1.0).describe('Gamma correction'),
      save: z.object({
        name: z.string().max(MAX_NAME_LENGTH),
        description: z.string().max(MAX_DESCRIPTION_LENGTH).optional(),
        category: z.string().max(MAX_NAME_LENGTH),
        tags: z.array(z.string().max(MAX_TAG_LENGTH)).max(MAX_TAGS),
      }).optional().describe('Save the converted art to the store'),
    },
  • TypeScript interface defining the options for convertImage function. Specifies optional width, height, invert, contrast, and gamma parameters for image conversion configuration.
    export interface ConvertOptions {
      width?: number;
      height?: number;
      invert?: boolean;
      contrast?: boolean;
      gamma?: number;
    }
  • Supporting constants for the convert tool - the ASCII character ramp used to map brightness levels to characters, from darkest (space) to lightest (@).
    import sharp from 'sharp';
    
    const ASCII_RAMP = ' .:-=+*#%@';
    const RAMP_LEN = ASCII_RAMP.length - 1;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description fails to disclose critical behavioral traits: the optional 'save' parameter persists data to a store (side effect), the output format/type is unspecified, and there's no mention of mutual exclusivity between URL and base64 inputs or error handling for invalid images.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The single-sentence description is efficiently structured with the action verb front-loaded. However, its extreme brevity contributes to the lack of behavioral transparency and contextual completeness, suggesting it is overly concise for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 7 parameters including a nested save object, no output schema, and zero annotations, the description is incomplete. It omits the return value format, fails to explain the persistence behavior of the save parameter, and provides no guidance on parameter interdependencies.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, establishing a baseline of 3. The description mentions 'size tier' and 'URL or base64' which align with the schema but add minimal semantic depth beyond what the schema property descriptions already provide.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool converts images to ASCII art and identifies the input sources (URL or base64) and the size tier concept. However, it does not explicitly distinguish this tool from siblings like 'banner' or 'kaomoji' which may also generate text art.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, nor does it explain prerequisites (e.g., that either URL or base64 must be provided despite neither being marked required) or when to use the save feature.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/rxolve/artscii'

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