Skip to content

Getting Started ​

Pixu delivers the best perceptual compression for the web by optimizing Contextual Reconstructive Entropy — (L(x \mid M, C, \varepsilon)) — via the PIXU format. Zero dependencies, full TypeScript, Shannon-honest science.

Read the TECR theory for the full model.

Installation ​

bash
npm install @pantanal/pixu
bash
yarn add @pantanal/pixu
bash
pnpm add @pantanal/pixu

First Compression ​

Try it live

Pick a sample or upload your own image

Try a sample image
typescript
import { compress } from '@pantanal/pixu';

const file = document.querySelector('input[type="file"]').files[0];

const result = await compress(file, {
  format: 'image/pixu',
  enableSmartQuality: true,
  stripMetadata: true,
});

console.log(`${result.originalSize} → ${result.compressedSize} bytes`);
console.log(`${(result.compressionRatio * 100).toFixed(1)}% reduction`);

Compression Options ​

typescript
const result = await compress(file, {
  quality: 0.8,
  maxWidth: 1920,
  maxHeight: 1080,
  format: 'auto',
  stripMetadata: true,
  fixOrientation: true,
  enableSmartQuality: true,
});

Output Formats ​

FormatMIMEExtensionBest for
PIXUimage/pixu.webp / .jpgTECR encode path; native WebP or JPEG output
WebPimage/webp.webpModern browsers
AVIFimage/avif.avifNative AVIF pipelines
JPEGimage/jpeg.jpgUniversal compatibility
PNGimage/png.pngTransparency, graphics
Autoauto—Prefers PIXU encode path when possible
typescript
import { compress, PIXU_MIME_TYPE, buildDownloadName } from '@pantanal/pixu';

const result = await compress(file, { format: PIXU_MIME_TYPE });
console.log(result.format); // "image/webp" or "image/jpeg"
console.log(buildDownloadName('out', result.format));

Learn more: PIXU Format · Supported Formats

Compression Modes ​

Quality mode ​

typescript
await compress(file, { mode: 'quality', quality: 0.8 });

Size mode ​

typescript
await compress(file, { mode: 'size', targetSize: 500 * 1024 });

Adaptive mode ​

typescript
await compress(file, { mode: 'adaptive' });

Resize Modes ​

typescript
await compress(file, {
  width: 1920,
  height: 1080,
  resize: 'contain',
});
ModeBehavior
noneNo resize
containFit inside box, keep aspect ratio
coverFill box, crop if needed
fitSame as contain
fillExact dimensions, may distort

Try Sample Images ​

The framework examples include real photos you can click to compress instantly:

typescript
import { compress } from '@pantanal/pixu';

const res = await fetch('/photo-landscape.jpg');
const blob = await res.blob();
const file = new File([blob], 'photo-landscape.jpg', { type: blob.type });

const result = await compress(file, { format: 'image/pixu' });

Or use a UI component with built-in samples:

vue
<PixuCompressor
  :samples="sampleImages"
  :options="{ quality: 0.85, format: 'image/pixu' }"
  @compress="onDone"
/>

Framework Examples ​

Prefer a full app? Pick your stack:

FrameworkGuide
Vue 3Vue Examples
ReactReact Examples
AngularAngular Examples
SvelteSvelte Examples
JacaréJacaré Examples

Run any project:

bash
npm run build          # from repo root
cd examples/vue        # or react, angular, svelte, jacare
npm install && npm run dev

Next Steps ​

Released under the MIT License.