Skip to main content
Glama

get_image_info

Extract image metadata and technical details from files or data inputs to analyze format, dimensions, and properties for informed processing decisions.

Instructions

获取图片文件信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_pathNo图片文件路径(与image_data二选一)
image_dataNo图片数据(Buffer或base64字符串,与image_path二选一)

Implementation Reference

  • src/index.ts:173-189 (registration)
    Registration of the 'get_image_info' tool in the ListTools handler, including its name, description, and input schema.
    {
      name: 'get_image_info',
      description: '获取图片文件信息',
      inputSchema: {
        type: 'object',
        properties: {
          image_path: {
            type: 'string',
            description: '图片文件路径(与image_data二选一)'
          },
          image_data: {
            type: 'string',
            description: '图片数据(Buffer或base64字符串,与image_path二选一)'
          }
        }
      }
    },
  • MCP handler for 'get_image_info' tool in the CallToolRequestHandler switch statement. It calls converter.getImageInfo and formats the response text.
    case 'get_image_info': {
      const { image_path, image_data } = args as { image_path?: string; image_data?: string };
      const info = await this.converter.getImageInfo(image_path, image_data);
      const source = image_path ? `文件路径:${image_path}` : '上传文件';
      return {
        content: [
          {
            type: 'text',
            text: `图片信息:\n${source}\n格式:${info.format}\n尺寸:${info.width}x${info.height}\n文件大小:${info.size} bytes\n颜色通道:${info.channels}\n颜色空间:${info.space || '未知'}`
          }
        ]
      };
    }
  • ImageInfo interface defining the structure of image information returned by getImageInfo.
    export interface ImageInfo {
      format: string;
      width: number;
      height: number;
      channels: number;
      size: number;
      space?: string;
    }
  • Core implementation of getImageInfo in ImageConverter class using Sharp to extract metadata from image file or buffer.
    async getImageInfo(imagePath?: string, imageData?: Buffer | string): Promise<ImageInfo> {
      try {
        let buffer: Buffer;
        let size: number;
    
        if (imageData) {
          if (typeof imageData === 'string') {
            const base64Data = imageData.includes(',') ? imageData.split(',')[1] : imageData;
            buffer = Buffer.from(base64Data, 'base64');
          } else {
            buffer = imageData;
          }
          size = buffer.length;
        } else if (imagePath) {
          await fs.access(imagePath);
          const stats = await fs.stat(imagePath);
          buffer = await fs.readFile(imagePath);
          size = stats.size;
        } else {
          throw new Error('必须提供imagePath或imageData参数');
        }
    
        const metadata = await sharp(buffer).metadata();
    
        return {
          format: metadata.format || 'unknown',
          width: metadata.width || 0,
          height: metadata.height || 0,
          channels: metadata.channels || 0,
          size: size,
          space: metadata.space
        };
      } catch (error) {
        throw new Error(`无法获取图片信息: ${error instanceof Error ? error.message : String(error)}`);
      }
    }

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/pickstar-2002/image-mcp'

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