Compress user-uploaded photos before sending them to a server to reduce bandwidth and storage costs.
Batch-compress a list of images in the background on Android without blocking the UI using coroutines.
Reduce image file sizes before displaying them in a gallery or feed to improve app memory usage.
Integrate image compression in a Java Android project using the legacy Builder-style API.
Luban 2 is an Android library that compresses photos and images before your app uploads or displays them. Modern phone cameras produce large image files, and sending these full-size files is slow and expensive. The library applies a compression algorithm designed to closely match the results you get when sending photos through WeChat Moments, producing small file sizes while keeping visual quality close to the original. The compression logic is adaptive: it analyzes each image based on its pixel count and dimensions, then applies a different strategy depending on what kind of image it is. Very small images are barely compressed to avoid quality loss. Standard photos get a balanced approach. Very large or panoramic images are compressed more aggressively. If the compressed result would actually be larger than the original, the library automatically passes through the original file instead, ensuring you never make things worse. This is a Kotlin rewrite of the original Luban library. It uses Kotlin Coroutines for asynchronous processing (so compression does not block the user interface) and TurboJPEG for the low-level encoding step. Kotlin projects can call it using a clean DSL or extension functions. Java projects can use a legacy Builder-style API. The library accepts files, URIs, and lists of images as input. Benchmark results in the README show the library compressing a 5.1 MB standard photo down to 305 KB, compared to WeChat reducing the same photo to 303 KB. For a 12.1 MB high-resolution image, the library produces 318 KB while WeChat produces 305 KB. The gap is small and the README is upfront that the algorithm is based on reverse engineering rather than access to WeChat internals. The library is available on Maven Central and works on Android API level 21 and above. It is licensed under the Apache 2.0 license.
← curzibn on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.