Luban 2 compresses photos in Android apps using an adaptive algorithm tuned to stay close to WeChat Moments output. It offers Kotlin coroutines, Java builder APIs, and TurboJPEG-backed processing.
Overview
Luban 2 is an Android library that shrinks camera and screenshot images while keeping visual quality acceptable for social-style sharing. Its compression targets were derived by comparing many resolutions against WeChat Moments exports, so results stay near that reference without manual trial and error on crop and quality settings.
The library applies adaptive unified image compression: it picks resolution and bitrate from the source dimensions. Short edges default to a 1440px baseline, panoramic images get a dedicated long-edge rule, very large pixel counts are downsampled, and extra-tall screenshots are capped to limit memory use. Small PNGs can keep transparency; larger PNGs may convert to JPEG, and outputs that grow versus the original fall back to the untouched file.
Developers add it from Maven Central and call it through Kotlin DSL, extension functions, or legacy static and builder-style Java APIs. Single files, URI inputs, and batches can run asynchronously with coroutines. Compression writes to a chosen output directory or a specific output file.
Compared with the original Luban release, this version rebuilds the core in Kotlin, adds coroutine-friendly flows, and leans on TurboJPEG for speed and robustness across common photo, panorama, and long-screenshot cases.
Key features
- Adaptive resolution and bitrate rules
- Kotlin coroutines and DSL APIs
- Java builder-compatible API
- Panorama and long-image safeguards
- PNG transparency or JPEG transcode
- Fallback when compression enlarges file
- Batch and single-file compression
- TurboJPEG-backed encoding
Use cases
- Shrinking camera uploads in Android apps
- Social feed image size control
- Screenshot compression before upload
- Batch gallery export compression