mirror of
https://github.com/status-im/react-native-image-crop-picker.git
synced 2025-02-22 10:28:23 +00:00
This reverts commit 97ce8bab5245953f78909bc9b34a27c861c6ec99.
This commit is contained in:
parent
97ce8bab52
commit
86e771d28d
@ -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;
|
||||
@ -20,19 +17,12 @@ import java.io.IOException;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -537,11 +537,11 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user