Skip to content

Commit

Permalink
feat: iOS - determine the output image type from the input image type (
Browse files Browse the repository at this point in the history
  • Loading branch information
takameyer authored and Trancever committed Nov 18, 2019
1 parent 747edcd commit bc0f93a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ios/RNCImageEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ @implementation RNCImageEditor
[RCTConvert CGPoint:cropData[@"offset"]],
[RCTConvert CGSize:cropData[@"size"]]
};
NSURL *url = [imageRequest URL];
NSString *urlPath = [url path];
NSString *extension = [urlPath pathExtension];

[_bridge.imageLoader loadImageWithURLRequest:imageRequest callback:^(NSError *error, UIImage *image) {
if (error) {
Expand All @@ -72,15 +75,25 @@ @implementation RNCImageEditor
}

// Store image
NSString *path = [RNCFileSystem generatePathInDirectory:[[RNCFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"ReactNative_cropped_image_"] withExtension:@".jpg"];
NSString *path = NULL;
NSData *imageData = NULL;

if([extension isEqualToString:@"png"]){
imageData = UIImagePNGRepresentation(croppedImage);
path = [RNCFileSystem generatePathInDirectory:[[RNCFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"ReactNative_cropped_image_"] withExtension:@".png"];
}
else{

imageData = UIImageJPEGRepresentation(croppedImage, 1);
path = [RNCFileSystem generatePathInDirectory:[[RNCFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"ReactNative_cropped_image_"] withExtension:@".jpg"];
}

NSData *imageData = UIImagePNGRepresentation(croppedImage);
NSError *writeError;
NSString *uri = [RNCImageUtils writeImage:imageData toPath:path error:&writeError];

if (writeError != nil) {
reject(@(writeError.code).stringValue, writeError.description, writeError);
return;
reject(@(writeError.code).stringValue, writeError.description, writeError);
return;
}

resolve(uri);
Expand Down

0 comments on commit bc0f93a

Please sign in to comment.