Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds forceJpg flag to convert live photos #791

Merged
merged 3 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class App extends Component {
multiple: true,
waitAnimationEnd: false,
includeExif: true,
forgeJpg: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a typo here in "forge"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, will do a follow-up PR

}).then(images => {
this.setState({
image: null,
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (instancetype)init
@"loadingLabelText": @"Processing assets...",
@"mediaType": @"any",
@"showsSelectedCount": @YES,
@"forceJpg": @NO,
@"cropperCancelText": @"Cancel",
@"cropperChooseText": @"Choose"
};
Expand Down Expand Up @@ -276,7 +277,7 @@ - (BOOL)cleanTmpDirectory {
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 = @{
Expand Down Expand Up @@ -509,7 +510,7 @@ - (void)qb_imagePickerController:
PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
options.synchronous = NO;
options.networkAccessAllowed = YES;

if ([[[self options] objectForKey:@"multiple"] boolValue]) {
NSMutableArray *selections = [[NSMutableArray alloc] init];

Expand Down Expand Up @@ -559,6 +560,8 @@ - (void)qb_imagePickerController:
[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);
Expand All @@ -573,7 +576,7 @@ - (void)qb_imagePickerController:
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);
Expand Down