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/wav | Stable |
⚠️ 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:
- TypeScript
- PHP
- Python
- Rust
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);
use Gisl\Sdk\Generated\SdkSpec\Enums\OptimizeFor;
$run = $client->file('./photo.jpg')
->compress(OptimizeFor::Size) // or Balanced / Quality
->run(maxWait: '5m');
echo $run->url;
Coming soon.
Coming soon.
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:
- TypeScript
- PHP
- Python
- Rust
const result = await client
.compress('./photo.jpg', { quality: 80 })
.run({ maxWait: '5m' });
console.log(`${result.artifacts[0].filename} — ${result.artifacts[0].sizeBytes} bytes`);
use Gisl\Sdk\Ergonomic\RunOptions;
$result = $client
->compress('./photo.jpg', ['quality' => 80])
->run(new RunOptions(maxWait: '5m'));
echo "{$result->artifacts[0]->filename} — {$result->artifacts[0]->sizeBytes} bytes\n";
Coming soon.
Coming soon.
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
- TypeScript
- PHP
- Python
- Rust
const many = await client
.files(['./a.jpg', './b.png', './c.webp'])
.compress(OptimizeFor.Balanced)
.run();
$many = $client->files(['./a.jpg', './b.png', './c.webp'])
->compress(OptimizeFor::Balanced)
->run();
Coming soon.
Coming soon.