Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vinodbaste/Image-compressor

An Android Image compress library, reduce's the size of the image by 90% without losing any of its pixels.
https://github.com/vinodbaste/Image-compressor

android android-app android-application android-development android-library android-plugin androidstudio compression compression-library dependencies developwithgoogle gradle-android-plugin image-compressor jetpack-compose kotlin kotlin-android photos

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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.

[![Google DevLibrary - VinodBaste](https://img.shields.io/badge/Google_DevLibrary-VinodBaste-ea9f2d?logo=Android<%2Ftitle><%2Fsvg>&logoColor=30DC80)](https://devlibrary.withgoogle.com/products/android/repos/vinodbaste-Image-compressor)

[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
[![GitHub tag](https://img.shields.io/github/tag/vinodbaste/image-compressor?include_prereleases=&sort=semver&color=blue)](https://github.com/vinodbaste/image-compressor/releases/)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue)](#license)
[![News - Android Weekly](https://img.shields.io/badge/News-Android_Weekly-d36f21)](https://androidweekly.net/issues/issue-326)
[![Story - Medium](https://img.shields.io/badge/Story-Medium-2ea44f)](https://medium.com/codex/image-compressor-13dbfd0445a3)
[![GitHub - VinodBaste](https://img.shields.io/badge/GitHub-VinodBaste-4664c6)](https://github.com/vinodbaste/Image-compressor)
[![](https://jitpack.io/v/vinodbaste/Image-compressor.svg)](https://jitpack.io/#vinodbaste/Image-compressor)

# 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:
```kotlin
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

`Step 2:` Add the dependency in your **project build.gradle**
```kotlin
dependencies {
implementation 'com.github.vinodbaste:ImageCompressor:1.1.0'
}
```
# 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**.
```kotlin
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`
```kotlin
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.
```kotlin
//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 {
(...);
}

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

**If you find this library useful, please consider starring this repository from the top of this page.**
[![](https://i.imgur.com/oSLuE0e.png)](#)

# Support my work
Buy Me A Coffee

# 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.
```