Skip to main content
Glama

compress_image

Reduce image file size without compromising quality by specifying input and output paths, compression quality, and progressive encoding for JPEGs.

Instructions

Compress an image with quality settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to input image
outputPathYesPath to save compressed image
progressiveNoUse progressive encoding (for JPEG)
qualityNoCompression quality (1-100)

Implementation Reference

  • Handler function for compress_image tool. Compresses image using sharp library based on detected format and quality settings, computes size reduction, and returns success message.
    case 'compress_image': { const { inputPath, outputPath, quality = 80, progressive = true } = args; await fs.mkdir(path.dirname(outputPath), { recursive: true }); const metadata = await sharp(inputPath).metadata(); let pipeline = sharp(inputPath); // Apply compression based on format if (metadata.format === 'jpeg') { pipeline = pipeline.jpeg({ quality, progressive }); } else if (metadata.format === 'png') { pipeline = pipeline.png({ quality }); } else if (metadata.format === 'webp') { pipeline = pipeline.webp({ quality }); } else if (metadata.format === 'avif') { pipeline = pipeline.avif({ quality }); } await pipeline.toFile(outputPath); const originalSize = (await fs.stat(inputPath)).size; const compressedSize = (await fs.stat(outputPath)).size; const savings = ((originalSize - compressedSize) / originalSize * 100).toFixed(1); return { content: [ { type: 'text', text: `Image compressed successfully. Saved to: ${outputPath}\nSize reduction: ${savings}% (${originalSize} → ${compressedSize} bytes)` } ] }; }
  • Input schema definition for compress_image tool, including parameters for input/output paths, quality, and progressive encoding.
    name: 'compress_image', description: 'Compress an image with quality settings', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save compressed image' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Compression quality (1-100)', default: 80 }, progressive: { type: 'boolean', description: 'Use progressive encoding (for JPEG)', default: true } }, required: ['inputPath', 'outputPath'] } },
  • src/index.ts:94-116 (registration)
    Registration of the compress_image tool in the ListTools response, including name, description, and schema.
    name: 'compress_image', description: 'Compress an image with quality settings', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save compressed image' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Compression quality (1-100)', default: 80 }, progressive: { type: 'boolean', description: 'Use progressive encoding (for JPEG)', default: true } }, required: ['inputPath', 'outputPath'] } },

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

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