-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
839 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,132 @@ | ||
# Resizer | ||
An image resizing library for Android | ||
[![](https://jitpack.io/v/hkk595/Resizer.svg)](https://jitpack.io/#hkk595/Resizer) | ||
|
||
Inspired by zetbaitsu's [Compressor](https://github.com/zetbaitsu/Compressor), Resizer is a lightweight and easy-to-use Android library for image resizing. It allows you to create a smaller or bigger image from the original image while keeping the aspect ratio. | ||
|
||
#### Include Resizer into your project | ||
1. Add the JitPack repository to your top-level build.gradle at the end of repositories | ||
```groovy | ||
allprojects { | ||
repositories { | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
2. Add the dependency in your module-level build.gradle | ||
```groovy | ||
dependencies { | ||
compile 'com.github.hkk595:Resizer:v1.0' | ||
} | ||
``` | ||
|
||
#### Pass in the original image file and get the resized image as a new file | ||
```java | ||
File resizedImage = new Resizer(this) | ||
.setTargetLength(1080) | ||
.setQuality(80) | ||
.setOutputFormat("JPEG") | ||
.setDestinationDirPath(storagePath) | ||
.setSourceImage(originalImage) | ||
.getResizedFile(); | ||
``` | ||
#### Pass in the original image file and get the resized image as a new bitmap | ||
```java | ||
Bitmap resizedImage = new Resizer(this) | ||
.setTargetLength(1080) | ||
.setSourceImage(originalImage) | ||
.getResizedBitmap(); | ||
``` | ||
Note: You only need to specify the target length (in pixel) of the longer side of the image. Resizer will calculate the rest automatically. | ||
|
||
#### Using RxJava to get the resized image asynchronously | ||
```java | ||
final File[] resizedImage = new File[1]; | ||
new Resizer(this) | ||
.setTargetLength(1080) | ||
.setQuality(80) | ||
.setOutputFormat("JPEG") | ||
.setDestinationDirPath(storagePath) | ||
.setSourceImage(originalImage) | ||
.getResizedFileAsFlowable() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe(new Consumer<File>() { | ||
@Override | ||
public void accept(File file) { | ||
resizedImage[0] = file; | ||
} | ||
}, new Consumer<Throwable>() { | ||
@Override | ||
public void accept(Throwable throwable) { | ||
throwable.printStackTrace(); | ||
} | ||
}); | ||
``` | ||
```java | ||
final Bitmap[] resizedImage = new Bitmap[1]; | ||
new Resizer(this) | ||
.setTargetLength(1080) | ||
.setSourceImage(originalImage) | ||
.getResizedBitmapAsFlowable() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe(new Consumer<Bitmap>() { | ||
@Override | ||
public void accept(Bitmap bitmap) { | ||
resizedImage[0] = bitmap; | ||
} | ||
}, new Consumer<Throwable>() { | ||
@Override | ||
public void accept(Throwable throwable) { | ||
throwable.printStackTrace(); | ||
} | ||
}); | ||
``` | ||
Note: You don't need to declare the new image as final nor array if it is an instance variable of the class, instead of a local variable in a function. | ||
|
||
#### Library specification | ||
Default settings: | ||
targetLength: 1080 | ||
quality: 80 | ||
outputFormat: JPEG | ||
destinationDirPath: the external files directory of your app | ||
Supported input formats: | ||
BMP | ||
GIF | ||
JPEG | ||
PNG | ||
WEBP | ||
Supported output formats: | ||
JPEG | ||
PNG | ||
WEBP | ||
Supported quality range: | ||
0~100 | ||
The higher number the better in image quality and larger in file size | ||
PNG, which is a lossless format, will ignore the quality setting | ||
|
||
## License | ||
MIT License | ||
Copyright (c) 2017 K.K. Ho | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
group='com.github.hkk595' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.3.1' | ||
testCompile 'junit:junit:4.12' | ||
|
||
compile 'io.reactivex.rxjava2:rxjava:2.1.3' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/Ho/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/me/echodev/resizer/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.echodev.resizer; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("me.echodev.resizer", appContext.getPackageName()); | ||
} | ||
} |
Oops, something went wrong.