react-native-image-resizer
react-native-image-resizer copied to clipboard
keepMeta is not working on iOS
I want to keep metadata when resizing an image.
I used ImageResizer.createResizedImage with keepMeta = true.
However, it is not working on iOS.
As a result of the analysis, getImageMeta() function is not working. It returns before getting the metadata from an image URI.
NSMutableDictionary * getImageMeta(NSString * path)
{
if([path hasPrefix:@"assets-library"]) {
__block NSMutableDictionary* res = nil;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
// (1) here asynchronous processing
NSDictionary *exif = [[myasset defaultRepresentation] metadata];
res = [exif mutableCopy];
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[assetslibrary assetForURL:url resultBlock:resultblock failureBlock:^(NSError *error) { NSLog(@"error couldn't image from assets library"); }];
// (2) result is returned before (1) is finished.
return res;
}
this issue can be prevented by using semaphore system.
environment
iPhoneSE 2generation (IOS 14.81) / iPhone12ProMax (iOS 15.1) react-native: 0.63.4 react-native-image-resizer: 1.4.5
Hello, we've got exactly the same problem, on IOS the getImageMeta method returns null.
Is a fix on the way or is it exist a way to prevent that comportment ?
@ishikawa-takumi have you success to implement the semaphore patch you talked in your post ?
environment
iPhoneXR (IOS 15.1) / iPhone12 (iOS 15.1) react-native: 0.63.4 react-native-image-resizer: 1.4.5
@odexvy
Yes, I have prevented this issue applying the following code.
node_modules/react-native-image-resizer/ios/RCTImageResizer.m
NSMutableDictionary * getImageMeta(NSString * path)
{
if([path hasPrefix:@"assets-library"] ) {
__block NSMutableDictionary* res = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
@try {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
NSDictionary *exif = [[myasset defaultRepresentation] metadata];
res = [exif mutableCopy];
dispatch_semaphore_signal(semaphore);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[assetslibrary assetForURL:url resultBlock:resultblock failureBlock:^(NSError *error) { NSLog(@"error couldn't image from assets library"); }];
});
}
@finally {
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC);
dispatch_semaphore_wait(semaphore, time);
return res;
}
} else {
thank you very much @ishikawa-takumi 👍
So keepMeta doesn't work for files in the assets library? Or it doesn't work for any file? I've been using it fine for images taken by the camera, saved into the app's local storage (documents folder), and then resizing it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed. Thank you for your contributions.