deflato
v1.2.0
Published
Deflato — compress images & documents, generate and edit AI images
Downloads
20
Maintainers
Readme
Deflato
Compress images, documents, and generate AI images with one line of code. Powered by deflato.com.
Install
npm install deflatoQuick Start
const Deflato = require('deflato');
const client = new Deflato('your-api-key');
// Compress an image
const result = await client.compress('photo.jpg', {
format: 'WEBP',
quality: 75,
maxDimension: 1920,
});
console.log(`Saved ${result.savingsPercent}% → ${result.outputPath}`);
// Compress a PDF document
const doc = await client.compressDocument('report.pdf', { quality: 70 });
console.log(`PDF: ${doc.savingsPercent}% smaller`);
// Generate an AI image
const img = await client.generate('A sunset over mountains', { model: 'fast' });
console.log(`Generated → ${img.outputPath}`);
// Edit an image with AI
const edited = await client.edit('Add sunglasses to the person', {
filePath: 'portrait.jpg',
model: 'fast',
});
console.log(`Edited → ${edited.outputPath}`);
// Get alt-text for an image
const desc = await client.describe({ filePath: 'photo.jpg' });
console.log(desc.description);API
new Deflato(apiKey, options?)
| Option | Default | Description |
|---|---|---|
| baseUrl | https://deflato.com | API base URL |
client.compress(inputPath, options?)
Compress an image file.
| Option | Default | Description | |---|---|---| | output | auto | Output file path | | quality | 80 | Quality 1-100 | | maxDimension | 0 | Max width/height (0 = no resize) | | format | JPEG | JPEG, PNG, WEBP, or AVIF | | stripExif | true | Remove EXIF metadata |
Returns { success, inputSize, outputSize, savingsPercent, format, outputPath }
client.info(inputPath, options?)
Get compression info without saving the file.
| Option | Default | Description | |---|---|---| | quality | 80 | Quality 1-100 | | maxDimension | 0 | Max width/height | | format | JPEG | Output format |
Returns { success, input_size, output_size, input_dimensions, output_dimensions, savings_percent }
client.compressBatch(inputPaths, options?)
Compress multiple files sequentially. Same options as compress() + outputDir.
Returns array of compress results.
client.compressDocument(inputPath, options?)
Compress images inside PDF, DOCX, PPTX, or XLSX documents.
| Option | Default | Description | |---|---|---| | output | auto | Output file path | | quality | 75 | Image quality 1-100 | | maxDimension | 1920 | Max image dimension in px |
Returns { success, inputSize, outputSize, savingsPercent, outputPath }
client.convertFormat(inputPath, outputFormat, options?)
Convert an image to a different format (JPEG, PNG, WEBP, AVIF).
| Option | Default | Description | |---|---|---| | output | auto | Output file path |
Returns same as compress().
client.generate(prompt, options?)
Generate an image from a text prompt using AI.
| Option | Default | Description | |---|---|---| | model | photo | fast, photo, design, or icon | | aspectRatio | 1:1 | Aspect ratio | | style | any | Style for design/icon models | | resolution | 1K | 1K, 2K, or 4K (photo only) | | format | png | png or jpg | | output | auto | Output file path |
Returns { success, outputPath, outputSize, model, prompt }
client.edit(prompt, options)
Edit an existing image using AI instructions (img2img).
| Option | Default | Description | |---|---|---| | filePath | — | Path to local image file | | imageUrl | — | URL of the image (alternative) | | model | fast | fast (~10s) or precise (~30s) | | format | png | png or jpg | | output | auto | Output file path |
Provide either filePath or imageUrl.
Returns { success, outputPath, outputSize, model, prompt }
client.describe(options)
Generate AI alt-text / caption for an image. Free — no rate limit.
| Option | Default | Description | |---|---|---| | filePath | — | Path to local image file | | imageUrl | — | URL of the image (alternative) |
Returns { success, description }
Supported Formats
Image input: JPEG, PNG, WEBP, HEIC, TIFF, BMP, GIF, RAW (20+ formats)
Image output: JPEG, PNG, WEBP, AVIF
Document input: PDF, DOCX, PPTX, XLSX
Get an API Key
Sign up at deflato.com/account to get your free API key.
License
MIT
