Skip to main content

Compress

Reduce file size for images, video, audio, and documents. The SDK picks the right options for the input's media type.

Audio formats

Accepted
audio/aac · audio/flac · audio/mp4 · audio/mpeg · audio/ogg · audio/wavStable

⚠️ This list is specific to compress. Each operation accepts its own set — merge, for example, does not take audio/mp4. Do not carry a list from one page to another; call getSchema() for the authoritative set at runtime.

File-first with a preset

When you would rather express intent than tune numbers, use a file-first recipe with an OptimizeFor preset — Size, Balanced, or Quality:

import { gisl, OptimizeFor } from '@giveitsmaller/sdk';

const client = await gisl.create({ apiKey: 'REPLACE_ME_API_KEY' });

const result = await client
.file('./photo.jpg')
.compress(OptimizeFor.Size) // or Balanced / Quality
.run({ maxWait: '5m' });

console.log(result.url);

Per-call options

To set explicit encode options instead of a preset, pass them to the ergonomic compress(input, options) form. For lossy images, quality is a 1–100 encode quality:

const result = await client
.compress('./photo.jpg', { quality: 80 })
.run({ maxWait: '5m' });

console.log(`${result.artifacts[0].filename}${result.artifacts[0].sizeBytes} bytes`);

The exact option keys are media-type specific — and the file-first chain validates them before any upload, so a typo is caught locally rather than as a server 422. To fetch the authoritative, per-MIME option list at runtime, call getSchema() for the input's media type and operation.

A batch at once

const many = await client
.files(['./a.jpg', './b.png', './c.webp'])
.compress(OptimizeFor.Balanced)
.run();

See also