A Minifier is a lightweight (21KB) android library for image resizing, format changing and quality focusing in reduce file size.

Step 1: Install it

Add to Project-level build.gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add to Module-level build.gradle:

dependencies {
    implementation 'com.github.jeziellago:image-minifier:0.1.1'
}

Step 2: Compress Image

With an image file, apply one or multiples transformations:

MinifierFactory.create(context)
    .withImage(originalFile)
    .addTransformations {
        resize(1200, 720)
        convertTo(CompressFormat.JPEG)
    }
    .minify {
        onSuccess { minified -> /* success */ }
        onFailure { error -> /* failure */ }
    }

or use coroutines:

val minifiedFile: File = MinifierFactory.create(context)
    .withImage(originalFile)
    .addTransformations {
        resize(1200, 720)
        convertTo(CompressFormat.JPEG)
    }
    .minify(Dispatchers.IO)

Step 3: Apply Transformations

Resize:

resize(1200, 720)

Format:

convertTo(CompressFormat.JPEG)

Gray scale:

colorGrayScale()

Quality


quality(80)

Reference

Read more here.