explaingit

zetbaitsu/compressor

7,219KotlinAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A Kotlin Android library that shrinks photo file sizes before uploading or storing them, with a one-liner API and customizable quality, resolution, output format, and maximum file-size constraints.

Mindmap

mindmap
  root((compressor))
    What it does
      Shrink photo size
      Keep visual quality
    Configuration
      Target resolution
      Quality level
      Output format
      Max file size
    Tech
      Kotlin coroutines
      Android Gradle
    Audience
      Android developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Compress a user-selected photo before uploading it to a server to reduce bandwidth and storage costs.

USE CASE 2

Resize images to a specific resolution and quality level before saving them locally on a device.

USE CASE 3

Enforce a maximum file size on all shared images using a custom compression constraint.

Tech stack

KotlinAndroidGradleCoroutines

Getting it running

Difficulty · easy Time to first run · 5min
Use freely in commercial and open-source projects, attribution required when distributing modified versions.

In plain English

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.

Copy-paste prompts

Prompt 1
Using the Compressor Kotlin library, write code to compress a photo to under 200KB before uploading it to Firebase Storage.
Prompt 2
How do I use Compressor inside a Kotlin coroutine to compress an image in the background without blocking the UI thread?
Prompt 3
Show me how to write a custom constraint in Compressor that limits output to JPEG format and renames the file to lowercase.
Open on GitHub → Explain another repo

← zetbaitsu on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.