Compress a user-selected photo before uploading it to a server to reduce bandwidth and storage costs.
Resize images to a specific resolution and quality level before saving them locally on a device.
Enforce a maximum file size on all shared images using a custom compression constraint.
Compressor is an Android library that shrinks the file size of photos on a user's device. When someone takes a picture with their phone, the resulting image file can be several megabytes large. Compressor lets developers reduce that size before uploading, storing, or sharing the image, with the aim of keeping the visual quality close to the original. The library is written in Kotlin and designed to be added to an Android project with a single line in the build configuration. Basic use is a one-liner: pass the context and the image file, and get back a smaller compressed file. The library uses sensible defaults, so most projects can get started without configuration. For cases where the defaults are not enough, developers can customize the compression settings by specifying a target resolution, a quality level from 0 to 100, an output format such as JPEG or WebP, and a maximum file size in bytes. These constraints can be combined in any combination, and developers can also write their own custom constraints if they need behavior the library does not provide out of the box. One example shown in the documentation is a constraint that renames the output file to lowercase, which can be combined with the standard quality and format settings. The library uses Kotlin coroutines, which is the standard approach in modern Android development for running work off the main thread. Image compression can take noticeable time on large files, so doing it in a coroutine keeps the app responsive while the work runs in the background. The library also supports running compression on the main thread when needed, though the README implies this is less common. The project is licensed under the Apache 2.0 license, which permits use in both open-source and commercial applications.
← zetbaitsu on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.