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)
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"inputPath": "<inputPath>",
"outputPath": "<outputPath>",
"format": "<format>"
},
"name": "convert_format"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to input image | |
| outputPath | Yes | Path to save converted image | |
| format | Yes | Target format | |
| quality | No | Quality for lossy formats (1-100) |
Implementation Reference
- src/index.ts:232-265 (handler)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}` } ] }; } - src/index.ts:56-75 (schema)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'] } },