Skip to main content
Glama

convert-image

Transform image files into different formats using the MCP Media Processing Server. Specify input path, desired output format, and optional output filename or path for efficient conversion.

Instructions

Convert image to different format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesAbsolute path to input image file
outputFilenameNoOutput filename (only used if outputPath is not provided)
outputFormatYesDesired output format (e.g., jpg, png, webp, gif)
outputPathNoOptional absolute path for output file. If not provided, file will be saved in Downloads folder

Implementation Reference

  • The asynchronous handler function that executes the image conversion logic using ImageMagick's 'convert' command. It validates paths, constructs the output filename, runs the conversion, and returns success or error messages.
    async ({ inputPath, outputFormat, outputPath, outputFilename }) => { try { await checkImageMagick(); const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_converted.${outputFormat}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = `convert "${absoluteInputPath}" "${finalOutputPath}"`; await execSync(command); return { content: [ { type: "text", text: `Image successfully converted and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error converting image: ${errorMessage}`, }, ], }; } }
  • Zod schema defining the input parameters for the convert-image tool.
    { inputPath: z.string().describe("Absolute path to input image file"), outputFormat: z.string().describe("Desired output format (e.g., jpg, png, webp, gif)"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") },
  • src/index.ts:323-363 (registration)
    The server.tool registration call that defines the tool name, description, input schema, and handler function for 'convert-image'. Note: excerpt abbreviated for handler.
    server.tool( "convert-image", "Convert image to different format", { inputPath: z.string().describe("Absolute path to input image file"), outputFormat: z.string().describe("Desired output format (e.g., jpg, png, webp, gif)"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") }, async ({ inputPath, outputFormat, outputPath, outputFilename }) => { try { await checkImageMagick(); const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const defaultFilename = outputFilename || `${inputFileName}_converted.${outputFormat}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = `convert "${absoluteInputPath}" "${finalOutputPath}"`; await execSync(command); return { content: [ { type: "text", text: `Image successfully converted and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error converting image: ${errorMessage}`, }, ], }; } } );

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/maoxiaoke/mcp-media-processor'

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