Adds forceJpg flag to convert live photos (#791)
* Adds property to filter live photos * Force JPG image conversion * Renames forceJPG -> forceJpg
This commit is contained in:
parent
e3eb95d2ec
commit
729e1caed3
|
@ -125,6 +125,7 @@ ImagePicker.clean().then(() => {
|
|||
| loadingLabelText (ios only) | string (default "Processing assets...") | Text displayed while photo is loading in picker |
|
||||
| mediaType | string (default any) | Accepted mediaType for image selection, can be one of: 'photo', 'video', or 'any' |
|
||||
| showsSelectedCount (ios only) | bool (default true) | Whether to show the number of selected assets |
|
||||
| forceJpg (ios only) | bool (default false) | Whether to convert photos to JPG. This will also convert any Live Photo into its JPG representation |
|
||||
| showCropGuidelines (android only) | bool (default true) | Whether to show the 3x3 grid on top of the image during cropping |
|
||||
| hideBottomControls (android only) | bool (default false) | Whether to display bottom controls |
|
||||
| enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture |
|
||||
|
|
|
@ -134,6 +134,7 @@ export default class App extends Component {
|
|||
multiple: true,
|
||||
waitAnimationEnd: false,
|
||||
includeExif: true,
|
||||
forgeJpg: true,
|
||||
}).then(images => {
|
||||
this.setState({
|
||||
image: null,
|
||||
|
|
|
@ -27,6 +27,7 @@ declare module "react-native-image-crop-picker" {
|
|||
loadingLabelText?: string;
|
||||
mediaType?: string;
|
||||
showsSelectedCount?: boolean;
|
||||
forceJpg?: boolean;
|
||||
showCropGuidelines?: boolean;
|
||||
hideBottomControls?: boolean;
|
||||
enableRotationGesture?: boolean;
|
||||
|
|
|
@ -88,6 +88,7 @@ RCT_EXPORT_MODULE();
|
|||
@"loadingLabelText": @"Processing assets...",
|
||||
@"mediaType": @"any",
|
||||
@"showsSelectedCount": @YES,
|
||||
@"forceJpg": @NO,
|
||||
@"cropperCancelText": @"Cancel",
|
||||
@"cropperChooseText": @"Choose"
|
||||
};
|
||||
|
@ -276,7 +277,7 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||
imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]);
|
||||
imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] intValue]);
|
||||
imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue];
|
||||
|
||||
|
||||
NSArray *smartAlbums = [self.options objectForKey:@"smartAlbums"];
|
||||
if (smartAlbums != nil) {
|
||||
NSDictionary *albums = @{
|
||||
|
@ -509,7 +510,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
|
||||
options.synchronous = NO;
|
||||
options.networkAccessAllowed = YES;
|
||||
|
||||
|
||||
if ([[[self options] objectForKey:@"multiple"] boolValue]) {
|
||||
NSMutableArray *selections = [[NSMutableArray alloc] init];
|
||||
|
||||
|
@ -559,6 +560,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
[lock lock];
|
||||
@autoreleasepool {
|
||||
UIImage *imgT = [UIImage imageWithData:imageData];
|
||||
|
||||
Boolean forceJpg = [[self.options valueForKey:@"forceJpg"] boolValue];
|
||||
|
||||
NSNumber *compressQuality = [self.options valueForKey:@"compressImageQuality"];
|
||||
Boolean isLossless = (compressQuality == nil || [compressQuality floatValue] >= 0.8);
|
||||
|
@ -573,7 +576,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
Boolean isKnownMimeType = [mimeType length] > 0;
|
||||
|
||||
ImageResult *imageResult = [[ImageResult alloc] init];
|
||||
if (isLossless && useOriginalWidth && useOriginalHeight && isKnownMimeType) {
|
||||
if (isLossless && useOriginalWidth && useOriginalHeight && isKnownMimeType && !forceJpg) {
|
||||
// Use original, unmodified image
|
||||
imageResult.data = imageData;
|
||||
imageResult.width = @(imgT.size.width);
|
||||
|
|
Loading…
Reference in New Issue