Skip to content

Commit

Permalink
Add source files
Browse files Browse the repository at this point in the history
  • Loading branch information
hkk595 committed Sep 2, 2017
1 parent 214b8ca commit aee7d46
Show file tree
Hide file tree
Showing 18 changed files with 839 additions and 8 deletions.
146 changes: 140 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
.idea/

# Keystore files
*.jks

# Google Services (e.g. APIs or Firebase)
google-services.json

# Created by https://www.gitignore.io/api/linux,macos,android,windows,jetbrains

### Android ###
# Built application files
*.apk
*.ap_
Expand Down Expand Up @@ -40,16 +51,139 @@ captures/
.idea/dictionaries
.idea/libraries

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

### Android Patch ###
gen-external-apklibs

### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/linux,macos,android,windows,jetbrains
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Kakit Ho
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
Expand Down
132 changes: 131 additions & 1 deletion README.md
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.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions app/build.gradle
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'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
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
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());
}
}
Loading

0 comments on commit aee7d46

Please sign in to comment.