Using @capgo/capacitor-file-compressor
Capacitor File Compressor Plugin interface for image compression.
Install
bun add @capgo/capacitor-file-compressor
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { FileCompressor } from '@capgo/capacitor-file-compressor';
API at a glance
| Method | Description |
|---|---|
compressImage |
Compresses an image file with specified dimensions and quality settings. |
Examples
compressImage()
Compresses an image file with specified dimensions and quality settings.
import { FileCompressor } from '@capgo/capacitor-file-compressor';
// Web - Compress from file input
const fileInput = document.getElementById('file') as HTMLInputElement;
const file = fileInput.files[0];
const result = await FileCompressor.compressImage({
blob: file,
quality: 0.8,
width: 1200,
mimeType: 'image/jpeg'
});
const url = URL.createObjectURL(result.blob);
Full reference
Keep going from Using @capgo/capacitor-file-compressor
If you are using Using @capgo/capacitor-file-compressor to plan storage and file handling, connect it with @capgo/capacitor-file-compressor for the implementation detail in @capgo/capacitor-file-compressor, Getting Started for the implementation detail in Getting Started, @capgo/capacitor-data-storage-sqlite for the implementation detail in @capgo/capacitor-data-storage-sqlite, Using @capgo/capacitor-data-storage-sqlite for the native capability in Using @capgo/capacitor-data-storage-sqlite, and @capgo/capacitor-file for the implementation detail in @capgo/capacitor-file.