Skip to main content
Glama

convert_format

Convert images between JPEG, PNG, WebP, and AVIF formats with quality control for lossy compression.

Instructions

Convert image between formats (jpeg, png, webp, avif)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to input image
outputPathYesPath to save converted image
formatYesTarget format
qualityNoQuality for lossy formats (1-100)

Implementation Reference

  • The handler for the 'convert_format' tool. It processes the input arguments, creates the output directory if needed, uses Sharp to convert the image to the specified format with optional quality, saves it, and returns a success message.
    case 'convert_format': { const { inputPath, outputPath, format, quality = 80 } = args; await fs.mkdir(path.dirname(outputPath), { recursive: true }); let pipeline = sharp(inputPath); switch (format) { case 'jpeg': case 'jpg': pipeline = pipeline.jpeg({ quality, progressive: true }); break; case 'png': pipeline = pipeline.png({ quality }); break; case 'webp': pipeline = pipeline.webp({ quality }); break; case 'avif': pipeline = pipeline.avif({ quality }); break; } await pipeline.toFile(outputPath); return { content: [ { type: 'text', text: `Image converted to ${format} format. Saved to: ${outputPath}` } ] }; }
  • Input schema definition for the 'convert_format' tool, specifying parameters like inputPath, outputPath, format (enum), and optional quality.
    inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save converted image' }, format: { type: 'string', enum: ['jpeg', 'jpg', 'png', 'webp', 'avif'], description: 'Target format' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Quality for lossy formats (1-100)', default: 80 } }, required: ['inputPath', 'outputPath', 'format'] }
  • src/index.ts:53-76 (registration)
    Registration of the 'convert_format' tool in the ListTools response, including name, description, and input schema.
    { name: 'convert_format', description: 'Convert image between formats (jpeg, png, webp, avif)', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save converted image' }, format: { type: 'string', enum: ['jpeg', 'jpg', 'png', 'webp', 'avif'], description: 'Target format' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Quality for lossy formats (1-100)', default: 80 } }, required: ['inputPath', 'outputPath', 'format'] } },

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/flowy11/imagician'

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