Skip to content

Commit

Permalink
Rename method for output path
Browse files Browse the repository at this point in the history
  • Loading branch information
hkk595 committed Sep 21, 2017
1 parent 5773d94 commit e1c076f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
2. Add the dependency in your module-level build.gradle
```groovy
dependencies {
compile 'com.github.hkk595:Resizer:v1.1'
compile 'com.github.hkk595:Resizer:v1.2'
}
```

Expand All @@ -27,7 +27,7 @@ File resizedImage = new Resizer(this)
.setTargetLength(1080)
.setQuality(80)
.setOutputFormat("JPEG")
.setDestinationDirPath(storagePath)
.setOutputDirPath(storagePath)
.setSourceImage(originalImage)
.getResizedFile();
```
Expand All @@ -47,7 +47,7 @@ new Resizer(this)
.setTargetLength(1080)
.setQuality(80)
.setOutputFormat("JPEG")
.setDestinationDirPath(storagePath)
.setOutputDirPath(storagePath)
.setSourceImage(originalImage)
.getResizedFileAsFlowable()
.subscribeOn(Schedulers.io())
Expand Down Expand Up @@ -87,11 +87,13 @@ new Resizer(this)
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
Minimum SDK: API 21
Default settings:
targetLength: 1080
quality: 80
outputFormat: JPEG
destinationDirPath: the external files directory of your app
outputDirPath: the external files directory of your app
Supported input formats:
BMP
Expand All @@ -105,9 +107,8 @@ Note: You don't need to declare the new image as final nor array if it is an ins
PNG
WEBP
Supported quality range:
0~100
The higher number the better in image quality and larger in file size
Supported quality range: 0~100
The higher value, the better image quality but larger file size
PNG, which is a lossless format, will ignore the quality setting

## License
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/me/echodev/resizer/Resizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public class Resizer {
private int targetLength, quality;
private Bitmap.CompressFormat compressFormat;
private String destinationDirPath;
private String outputDirPath;
private File sourceImage;

public Resizer(Context context) {
targetLength = 1080;
quality = 80;
compressFormat = Bitmap.CompressFormat.JPEG;
destinationDirPath = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();
outputDirPath = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();
}

public Resizer setTargetLength(int targetLength) {
Expand Down Expand Up @@ -53,8 +53,8 @@ public Resizer setOutputFormat(String outputFormat) {
return this;
}

public Resizer setDestinationDirPath(String destinationDirPath) {
this.destinationDirPath = destinationDirPath;
public Resizer setOutputDirPath(String outputDirPath) {
this.outputDirPath = outputDirPath;
return this;
}

Expand All @@ -64,7 +64,7 @@ public Resizer setSourceImage(File sourceImage) {
}

public File getResizedFile() throws IOException {
return ImageUtils.getScaledImage(targetLength, quality, compressFormat, destinationDirPath, sourceImage);
return ImageUtils.getScaledImage(targetLength, quality, compressFormat, outputDirPath, sourceImage);
}

public Bitmap getResizedBitmap() throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/echodev/resizer/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

public class FileUtils {
public static String getDestinationFilePath(Bitmap.CompressFormat compressFormat, String destinationDirPath, File sourceImage) {
public static String getDestinationFilePath(Bitmap.CompressFormat compressFormat, String outputDirPath, File sourceImage) {
String originalFileName = sourceImage.getName();
String targetFileName;
String targetFileExtension = "." + compressFormat.name().toLowerCase().replace("jpeg", "jpg");
Expand All @@ -23,7 +23,7 @@ public static String getDestinationFilePath(Bitmap.CompressFormat compressFormat
targetFileName = originalFileName.substring(0, extensionIndex) + targetFileExtension;
}

return destinationDirPath + File.separator + targetFileName;
return outputDirPath + File.separator + targetFileName;
}

public static void writeBitmapToFile(Bitmap bitmap, Bitmap.CompressFormat compressFormat, int quality, String filePath) throws IOException {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/me/echodev/resizer/util/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/

public class ImageUtils {
public static File getScaledImage(int targetLength, int quality, Bitmap.CompressFormat compressFormat, String destinationDirPath, File sourceImage) throws IOException {
File file = new File(destinationDirPath);
if (!file.exists()) {
file.mkdirs();
public static File getScaledImage(int targetLength, int quality, Bitmap.CompressFormat compressFormat, String outputDirPath, File sourceImage) throws IOException {
File directory = new File(outputDirPath);
if (!directory.exists()) {
directory.mkdirs();
}

// Prepare the new file name and path
String destinationFilePath = FileUtils.getDestinationFilePath(compressFormat, destinationDirPath, sourceImage);
String destinationFilePath = FileUtils.getDestinationFilePath(compressFormat, outputDirPath, sourceImage);

// Write the resized image to the new file
Bitmap scaledBitmap = getScaledBitmap(targetLength, sourceImage);
Expand Down

0 comments on commit e1c076f

Please sign in to comment.