A high-performance, lightweight image compression library for Compose Multiplatform (Android, iOS, Desktop/JVM, Web/WASM). It allows you to efficiently compress and resize images into high-quality WebP format using a simple, unified multiplatform API.
Key Features:
- ⚡ Dual Compression Modes: Compress by target quality percentage or target file size constraint (KB).
- 📐 Smart Resizing: Fast, aspect-ratio-aware resizing prior to compression to save memory and network bandwidth.
- ⚙️ Multi-Engine Execution: Uses high-performance native engines under the hood (Android's Bitmap, JVM's Skia, iOS's UIKit, Wasm's Canvas).
- 📊 Rich Analytics: Delivers metadata and diagnostics on compression ratios, elapsed times, and iteration counts.
- 🧪 Testable Design: Designed to support clean UI unit tests and portable multiplatform verification.
| Capability | Android | iOS | Desktop (JVM) | Web (WASM) |
|---|---|---|---|---|
| WebP Compression | ✅ | ✅ | ✅ | ✅ |
| Compress By Quality | ✅ | ✅ | ✅ | ✅ |
| Compress By Target Size | ✅ | ✅ (Iterative) | ✅ (Iterative) | ✅ (Iterative) |
| Smart Auto-Resizing | ✅ | ✅ | ✅ | ✅ |
| Compression Analytics | ✅ | ✅ | ✅ | ✅ |
Add the dependency to your Compose Multiplatform project:
Option A — Version Catalog (Recommended)
- In
gradle/libs.versions.toml:
[versions]
cmpImgcompress = "0.0.1"
[libraries]
cmp-imgcompress = { module = "io.github.aryapreetam:cmp-imgcompress", version.ref = "cmpImgcompress" }- In your module's
build.gradle.kts:
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.cmp.imgcompress)
}
}
}
}Option B — Direct Dependency
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.aryapreetam:cmp-imgcompress:0.0.1")
}
}
}
}import io.github.aryapreetam.cmpimgcompress.*
suspend fun compressMyImage(inputBytes: ByteArray) {
val imageData = ImageData(inputBytes, "image/png")
// Compress to WebP at 80% quality
val compressed: CompressedImage = ImageCompressor.compress(
input = imageData,
config = CompressionConfig.ByQuality(80f)
)
println("Original: ${compressed.originalSize} bytes")
println("Compressed: ${compressed.compressedSize} bytes")
val outputWebpBytes = compressed.bytes
}import io.github.aryapreetam.cmpimgcompress.*
suspend fun compressToLimit(inputBytes: ByteArray) {
val imageData = ImageData(inputBytes, "image/jpeg")
// Attempt to compress the image to fall under 100 KB
val compressed = ImageCompressor.compress(
input = imageData,
config = CompressionConfig.ByTargetSize(100), // Target size limit in KB
resize = ResizeOptions(maxLongEdgePx = 1920) // Optional resizing
)
println("Elapsed time: ${compressed.metadata?.elapsedMillis} ms")
println("Iterations taken: ${compressed.metadata?.iterations}")
}Download and try the sample app on your platform without building from source:
For instructions on how to install and run the pre-built executables or build and run the sample application from source code, please refer to the How to Run the Sample App guide.
MIT License © 2026 aryapreetam and contributors. See LICENSE for details.