Skip to content

Conversation

@skychx
Copy link
Contributor

@skychx skychx commented Jul 31, 2025

ImageCompressor

A high-performance image compression utility that supports multiple formats and quality settings.

Platform Compatibility

Node.js only.

Basic Usage

import { ImageCompressor } from '@agent-infra/media-utils';

// Create compressor with default options (WebP format, 80% quality)
const compressor = new ImageCompressor();

// Or with custom options
const customCompressor = new ImageCompressor({
  quality: 90,
  format: 'jpeg'
});

// Compress image buffer
const imageBuffer = new Uint8Array(/* your image data */);
const compressedBuffer = await compressor.compressToBuffer(imageBuffer);

Configuration Options

interface ImageCompressionOptions {
  quality?: number;    // 1-100, default: 80
  format?: 'jpeg' | 'png' | 'webp';  // default: 'webp'
  width?: number;      // optional width constraint
  height?: number;     // optional height constraint
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants