convert_format
Convert images between formats (JPEG, PNG, WebP, AVIF) with specified quality settings using Imagician’s MCP server. Input source and target paths to transform images efficiently.
Instructions
Convert image between formats (jpeg, png, webp, avif)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | Yes | Target format | |
| inputPath | Yes | Path to input image | |
| outputPath | Yes | Path to save converted image | |
| quality | No | Quality for lossy formats (1-100) |
Implementation Reference
- src/index.ts:232-265 (handler)The handler function for the 'convert_format' tool. It destructures arguments, ensures output directory exists, creates a Sharp pipeline for the input image, applies the specified format (with quality), saves to output path, 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 for the 'convert_format' tool defining parameters: 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'] } },