Skip to content

Commit

Permalink
Revert "Added android equivalent code to iOS code. (#749)" (#750)
Browse files Browse the repository at this point in the history
This reverts commit 97ce8ba.
  • Loading branch information
ivpusic authored Jul 3, 2018
1 parent 97ce8ba commit 86e771d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.reactnative.ivpusic.imagepicker;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableMap;
import id.zelory.compressor.Compressor;
import java.util.Arrays;
import java.util.List;

import java.io.File;
import java.io.IOException;
Expand All @@ -20,19 +17,12 @@

class Compression {

File compressImage(final Activity activity, final ReadableMap options, final String originalImagePath, final BitmapFactory.Options bitmapOptions) throws IOException {
File compressImage(final Activity activity, final ReadableMap options, final String originalImagePath) throws IOException {
Integer maxWidth = options.hasKey("compressImageMaxWidth") ? options.getInt("compressImageMaxWidth") : null;
Integer maxHeight = options.hasKey("compressImageMaxHeight") ? options.getInt("compressImageMaxHeight") : null;
Double quality = options.hasKey("compressImageQuality") ? options.getDouble("compressImageQuality") : null;

Boolean isLossLess = (quality == null || quality == 1.0);
Boolean useOriginalWidth = (maxWidth == null || maxWidth >= bitmapOptions.outWidth);
Boolean useOriginalHeight = (maxHeight == null || maxHeight >= bitmapOptions.outHeight);

List knownMimes = Arrays.asList("image/jpeg", "image/jpg", "image/png", "image/gif", "image/tiff");
Boolean isKnownMimeType = (bitmapOptions.mimeType != null && knownMimes.contains(bitmapOptions.mimeType.toLowerCase()));

if (isLossLess && useOriginalWidth && useOriginalHeight && isKnownMimeType) {
if (maxWidth == null && maxHeight == null && quality == null) {
Log.d("image-crop-picker", "Skipping image compression");
return new File(originalImagePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ private WritableMap getImage(final Activity activity, String path) throws Except
if (path.startsWith("http://") || path.startsWith("https://")) {
throw new Exception("Cannot select remote files");
}
BitmapFactory.Options original = validateImage(path);
validateImage(path);

// if compression options are provided image will be compressed. If none options is provided,
// then original image will be returned
File compressedImage = compression.compressImage(activity, options, path, original);
File compressedImage = compression.compressImage(activity, options, path);
String compressedImagePath = compressedImage.getPath();
BitmapFactory.Options options = validateImage(compressedImagePath);
long modificationDate = new File(path).lastModified();
Expand Down

0 comments on commit 86e771d

Please sign in to comment.