Skip to main content
Glama

get_image_size

Retrieve the dimensions (width and height) of an image directly from its URL for accurate sizing and processing in applications.

Instructions

Get the size of an image from URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
optionsYesOptions for retrieving image size

Implementation Reference

  • MCP tool handler that extracts the image URL from input options, calls the helper function getImageSizeFromUrl, formats the result as JSON text content, and handles errors.
    async ({ options = {} }) => { try { const { imageUrl } = options as { imageUrl: string }; // Call tool function implementation const result = await getImageSizeFromUrl(imageUrl); return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { throw new Error( `Failed to get image size: ${(error as Error).message}`, ); } },
  • Core helper function that uses probe-image-size to fetch and return width, height, type, and mime of an image from a given URL.
    export async function getImageSizeFromUrl(imageUrl: string) { // 获取图片尺寸信息 const imageInfo = await probe(imageUrl); return { width: imageInfo.width, height: imageInfo.height, type: imageInfo.type, mime: imageInfo.mime, }; }
  • Zod input schema defining the required 'imageUrl' string parameter for the tool.
    options: z .object({ imageUrl: z.string().describe("Url of the image to retrieve"), }) .describe("Options for retrieving image size"),
  • src/server.ts:169-198 (registration)
    Full registration of the 'get_image_size' tool on the MCP server, including name, description, schema, and handler implementation.
    server.tool( "get_image_size", "Get the size of an image from URL", { options: z .object({ imageUrl: z.string().describe("Url of the image to retrieve"), }) .describe("Options for retrieving image size"), }, async ({ options = {} }) => { try { const { imageUrl } = options as { imageUrl: string }; // Call tool function implementation const result = await getImageSizeFromUrl(imageUrl); return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { throw new Error( `Failed to get image size: ${(error as Error).message}`, ); } }, );

Other Tools

Related 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/kshern/image-tools-mcp'

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