An Android Image compress library, reduce's the size of the image by 90% without losing any of its pixels.

Overview

Image Compressor

An Android image compress library, image compressor, is small and effective. With very little or no image quality degradation, a compressor enables you to reduce the size of large photos into smaller size photos.

How to implement

To get a Git project into your build:

Gradle

Step 1: Add it in your root build.gradle at the end of repositories:

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

Step 2: Add the dependency in your project build.gradle

dependencies {
	        implementation 'com.github.vinodbaste:ImageCompressor:1.0.1'
}

Let's compress the image size!

Compress Image File at the specified imagePath

When compressing a picture, add the following block of code to the activity or fragment. Either after taking a picture with a camera or selecting one from a gallery.

ImageCompressUtils.compressImage(
            context = this,
            imagePath = "actualImagePath",
            imageName = "imageName",
            imageQuality = 50
        )

compressImage takes 4 parameters where the last one is optional

  • context, the current/active state of the application.
  • imagePath parameter takes the absolute image path.
  • imageName is completely up to the user.
  • imageQuality is set to 50 by default. The max can be set to 100.

Compress Image File at the specified imagePath and return the compressed ImagePath

val compressedImagePath = ImageCompressUtils.compressImage(
            context = this,
            imagePath = "actualImagePath",
            imageName = "imageName",
            imageQuality = 50
        )

With the image name supplied, the code block above returns the path to the compressed picture. compressedImagePath has the imagePath with the imageName specified.

Example

An illustration of how the code block can be utilized.

 	 //absolute path of the image
        val imagePath= "actualImagePath"

        val imageFileBc = File(imagePath)
        val imageSizeBc = imageFileBc.length() / 1024 // In BYTES
        Log.d("image_before_compress", imageSizeBc.toString())

        ImageCompressUtils.compressImage(
            context = this,
            imagePath = imagePath,
            imageName = "imageName",
            imageQuality = 50
        )

        val imageFileAc = File(imagePath)
        val imageSizeAC = imageFileAc.length() / 1024 // In BYTES
        Log.d("image_after_compress", imageSizeAC.toString())

        //your function to play with compressed image
        loadCompressedImage(imagePath) 

proguard-rules

-keepclassmembers class com.android.imagecompressor.compressImageUtils

-keep class * extends com.android.imagecompressor.compressImageUtils {
 <init>(...);
}

-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

Note

> In the event that an image is selected from a gallery, make a copy of it and follow the path.
> The original picture path is used to compress and rewrite the image.

License

Copyright [2022] [Vinod Baste]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
A multifunctional Android RAT with GUI based Web Panel without port forwarding.

AIRAVAT A multifunctional Android RAT with GUI based Web Panel without port forwarding. Features Read all the files of Internal Storage Download Any M

Quickly rotate screen on Android devices without second thought
Quickly rotate screen on Android devices without second thought

Useful uitlity for ONYX BOOX Eink devices. It provides several quick actions to be added in top system panel

A simple textfield for adding quick notes without ads.
A simple textfield for adding quick notes without ads.

Simple Notes A simple textfield for adding quick notes. Need to take a quick note of something to buy, an address, or a startup idea? Then this is the

Easy app for managing your files without ads, respecting your privacy & security
Easy app for managing your files without ads, respecting your privacy & security

Simple File Manager Can also be used for browsing root files and SD card content. You can easily rename, copy, move, delete and share anything you wis

DSL for JPA Criteria API without generated metamodel and reflection.
DSL for JPA Criteria API without generated metamodel and reflection.

Kotlin JDSL Kotlin JDSL is DSL for JPA Criteria API without generated metamodel and reflection. It helps you write a JPA query like writing an SQL sta

Send Whatsapp Message Without Saving Mobile Number

Send Whatsapp Message Without Saving Mobile Number In this project i created the

Guide to setup JetBrains Projector and access Android Studio from any device
Guide to setup JetBrains Projector and access Android Studio from any device

JetBrains Projector with Android Studio Guide to setup JetBrains Projector and access Android Studio from any device. Blog post Android Studio on an i

Android app to fetch closed pull request of any public repo

Pullr Android app to fetch closed pull request of any public repo 🌟 Features Co

Releases(1.0.1)
Owner
Vinod Baste
I design and develop experiences that make people's lives simple.
Vinod Baste
Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

mohsen 21 Dec 3, 2022
Automatically generates UI demos which allow users to call any function with any parameters

Automatically generates UI demos which allow users to call any function (including composable ones) with any parameters. Useful for building demo screens in playground apps of various design systems.

Anton Popov 3 Jul 28, 2022
Simple view which allow you to customise your pizza's toppings and size as per your choice.

TwistedPizzaToppingsView Overview Simple view which allows options to customize your pizza toppings and size as per your choice. Features Android 12 s

MindInventory 19 Dec 18, 2022
A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server

dadb Blog Post: Our First Open-Source Project A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server de

mobile.dev 791 Dec 20, 2022
An attendance recorder app for teachers. Its a part of Android Study Jams 2021 @ GDSC-NITA

Attendance-Pad An attendance recorder app for teachers, build for Android using Kotlin. This project is a part of Andoird Study Jams 2021 @ GDSC-NITA.

Developer Student Clubs - NIT Agartala 2 Jun 23, 2022
This assignment gives you basically a post list and its detail with comments.🚀

Android Assignment ?? Description This assignment gives you basically a post list and its detail with comments. ?? Features Users can see random post

Okan AYDIN 31 Dec 20, 2022
This repository contains RabbitMQ Protobuf starters with its usage samples for spring-rabbit and spring-cloud-starter-stream-rabbit modules

This repository contains RabbitMQ Protobuf starters with its usage samples for spring-rabbit and spring-cloud-starter-stream-rabbit modules

Maksim Kostromin 2 Nov 29, 2021
This App lists Maverl comics and its detail

DisneyCodeChallenge This App lists Maverl comics and its detail. Development Environment The app is written entirely in Kotlin and uses the Gradle bui

null 0 Nov 10, 2021
A backend service that generates a random 32-chars length message and its sha256 hashcode and put them to DB

This is an Android application in which a user can ask the server to generate a random message and its sha256, and ask to obtain this info from the server.

Iskander 1 Nov 20, 2022
This just checks what architecture an installed application is using for its libraries.

Architecture Checker This just checks what architecture an installed application is using for its libraries. About Recently, I've seen that many peopl

Rev 11 Jan 31, 2023