Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Next Next commit
support WebP for iOS
  • Loading branch information
TrGiLong committed Oct 23, 2021
commit a35b4bbcdacf4c29ec75f5fa7855404e76038c69
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,61 @@ - (void)start {
}
if (@available(iOS 14, *)) {
[self setExecuting:YES];
[self.result.itemProvider
loadObjectOfClass:[UIImage class]
completionHandler:^(__kindof id<NSItemProviderReading> _Nullable image,
NSError *_Nullable error) {
if ([image isKindOfClass:[UIImage class]]) {
__block UIImage *localImage = image;
PHAsset *originalAsset =
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:self.result];

if (self.maxWidth != (id)[NSNull null] || self.maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
maxWidth:self.maxWidth
maxHeight:self.maxHeight
isMetadataAvailable:originalAsset != nil];
}
__block NSString *savedPath;
if (!originalAsset) {
// Image picked without an original asset (e.g. User pick image without permission)
savedPath =
[FLTImagePickerPhotoAssetUtil saveImageWithPickerInfo:nil
image:localImage
imageQuality:self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
} else {
[[PHImageManager defaultManager]
requestImageDataForAsset:originalAsset
options:nil
resultHandler:^(
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
UIImageOrientation orientation, NSDictionary *_Nullable info) {
// maxWidth and maxHeight are used only for GIF images.
savedPath = [FLTImagePickerPhotoAssetUtil
saveImageWithOriginalImageData:imageData
image:localImage
maxWidth:self.maxWidth
maxHeight:self.maxHeight
imageQuality:self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
}];
}
}
NSString *webpIdentifier = @"org.webmproject.webp";
if ([self.result.itemProvider hasItemConformingToTypeIdentifier:webpIdentifier]) {
[self.result.itemProvider loadDataRepresentationForTypeIdentifier:webpIdentifier completionHandler:^(NSData * _Nullable data, NSError * _Nullable error) {
__block UIImage *image = [[UIImage alloc] initWithData:data];
[self processImage:image];
}];
return;
}

[self.result.itemProvider loadObjectOfClass:[UIImage class] completionHandler:^(__kindof id<NSItemProviderReading> _Nullable image, NSError *_Nullable error) {
if ([image isKindOfClass:[UIImage class]]) {
[self processImage:image];
}
}];
} else {
[self setFinished:YES];
}
}

- (void)processImage:(UIImage *)image API_AVAILABLE(ios(14)); {
__block UIImage *localImage = image;
PHAsset *originalAsset =
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:self.result];

if (self.maxWidth != (id)[NSNull null] || self.maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
maxWidth:self.maxWidth
maxHeight:self.maxHeight
isMetadataAvailable:originalAsset != nil];
}
__block NSString *savedPath;
if (!originalAsset) {
// Image picked without an original asset (e.g. User pick image without permission)
savedPath =
[FLTImagePickerPhotoAssetUtil saveImageWithPickerInfo:nil
image:localImage
imageQuality:self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
} else {
[[PHImageManager defaultManager]
requestImageDataForAsset:originalAsset
options:nil
resultHandler:^(
NSData *_Nullable imageData, NSString *_Nullable dataUTI,
UIImageOrientation orientation, NSDictionary *_Nullable info) {
// maxWidth and maxHeight are used only for GIF images.
savedPath = [FLTImagePickerPhotoAssetUtil
saveImageWithOriginalImageData:imageData
image:localImage
maxWidth:self.maxWidth
maxHeight:self.maxHeight
imageQuality:self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
}];
}
}

@end