[jira] [Commented] (CB-13950) All Exif data is stripped off under iOS when Camera.DestinationType is File_URI

2018-03-06 Thread Junran (JIRA)

[ 
https://issues.apache.org/jira/browse/CB-13950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16388678#comment-16388678
 ] 

Junran commented on CB-13950:
-

User Text to keep the line change: 

- (NSData*)processImage:(UIImage*)image info:(NSDictionary*)info 
options:(CDVPictureOptions*)options
{
NSData* data = nil;

switch (options.encodingType) {
case EncodingTypePNG:
data = UIImagePNGRepresentation(image);
break;
case EncodingTypeJPEG:
{
if ((options.allowsEditing == NO) && (options.targetSize.width <= 
0) && (options.targetSize.height <= 0) && (options.correctOrientation == NO) && 
(([options.quality integerValue] == 100) || (options.sourceType != 
UIImagePickerControllerSourceTypeCamera))){
// use image unedited as requested , don't resize
data = UIImageJPEGRepresentation(image, 1.0);
} else {
data = UIImageJPEGRepresentation(image, [options.quality 
floatValue] / 100.0f);
}

//if (options.usesGeolocation) {
 NSURL *assetURL = [info 
objectForKey:UIImagePickerControllerReferenceURL];
 
//NSDictionary *metadata =[info 
objectForKey:UIImagePickerControllerMediaMetadata];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_queue_t queue = 
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

dispatch_async(queue, ^{[library assetForURL:assetURL

resultBlock:^(ALAsset *asset)  {

NSDictionary *controllerMetadata = 
asset.defaultRepresentation.metadata;
   
//NSLog(@"metadatacontrol %@", controllerMetadata);

//NSDictionary* controllerMetadata = [info 
objectForKey:@"UIImagePickerControllerMediaMetadata"];
if (controllerMetadata) {
self.data = data;
self.metadata = [[NSMutableDictionary alloc] init];
NSMutableDictionary *metadataAsMutable = 
[controllerMetadata mutableCopy];
//NSMutableDictionary* EXIFDictionary = 
[[metadataAsMutable 
objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
NSMutableDictionary *EXIFDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyExifDictionary]mutableCopy];
NSMutableDictionary *GPSDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyGPSDictionary]mutableCopy];
NSMutableDictionary *RAWDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyRawDictionary]mutableCopy];

if(!EXIFDictionary)
EXIFDictionary = [[NSMutableDictionary dictionary] 
init];

if(!GPSDictionary)
GPSDictionary = [[NSMutableDictionary dictionary] 
init];

if(!RAWDictionary)
RAWDictionary = [[NSMutableDictionary dictionary] 
init];

//Add the modified Data back into the image’s metadata
[self.metadata setObject:EXIFDictionary 
forKey:(NSString *)kCGImagePropertyExifDictionary];
[self.metadata setObject:GPSDictionary forKey:(NSString 
*)kCGImagePropertyGPSDictionary];
[self.metadata setObject:RAWDictionary forKey:(NSString 
*)kCGImagePropertyRawDictionary];

//NSLog(@"enter gpsdictionary %@", GPSDictionary);
//NSLog(@"enter exifdictionary %@", EXIFDictionary);
//NSLog(@"enter rawdictionary %@", RAWDictionary);

//NSLog(@"enter self.metadata %@", self.metadata);
if (self.metadata) {
//this will be the data CGImageDestinationRef will 
write into
NSMutableData *newImageData = [NSMutableData data];

CGImageSourceRef sourceImage = 
CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL);
CFStringRef sourceType = 
CGImageSourceGetType(sourceImage);

CGImageDestinationRef destinationImage = 
CGImageDestinationCreateWithData((__bridge CFMutableDataRef)newImageData, 
sourceType, 1, NULL);

CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, 
(__bridge CFDictionaryRef)self.metadata);
CGImageDestinationFinalize(destinationImage);

//CIImage *testImage = [CIImage 
imageWithData:newImageData];
self.data = newImageData;

[jira] [Commented] (CB-13950) All Exif data is stripped off under iOS when Camera.DestinationType is File_URI

2018-03-06 Thread Junran (JIRA)

[ 
https://issues.apache.org/jira/browse/CB-13950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16388676#comment-16388676
 ] 

Junran commented on CB-13950:
-

I have changed the following function to keep the exif data when using 
File_URI, please use or make change as you see fit, any other suggestion or 
improvement is most welcome too:

 

- (NSData*)processImage:(UIImage*)image info:(NSDictionary*)info 
options:(CDVPictureOptions*)options
{
    NSData* data = nil;

    switch (options.encodingType) {
    case EncodingTypePNG:
    data = UIImagePNGRepresentation(image);
    break;
    case EncodingTypeJPEG:
    {
    if ((options.allowsEditing == NO) && (options.targetSize.width <= 
0) && (options.targetSize.height <= 0) && (options.correctOrientation == NO) && 
(([options.quality integerValue] == 100) || (options.sourceType != 
UIImagePickerControllerSourceTypeCamera))){
    // use image unedited as requested , don't resize
    data = UIImageJPEGRepresentation(image, 1.0);
    } else {
    data = UIImageJPEGRepresentation(image, [options.quality 
floatValue] / 100.0f);
    }

    //if (options.usesGeolocation) {
 NSURL *assetURL = [info 
objectForKey:UIImagePickerControllerReferenceURL];
 
    //NSDictionary *metadata =[info 
objectForKey:UIImagePickerControllerMediaMetadata];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    dispatch_queue_t queue = 
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

    dispatch_async(queue, ^{[library assetForURL:assetURL

    resultBlock:^(ALAsset *asset)  {

    NSDictionary *controllerMetadata = 
asset.defaultRepresentation.metadata;
   
    //NSLog(@"metadatacontrol %@", controllerMetadata);
    
    //NSDictionary* controllerMetadata = [info 
objectForKey:@"UIImagePickerControllerMediaMetadata"];
    if (controllerMetadata) {
    self.data = data;
    self.metadata = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *metadataAsMutable = 
[controllerMetadata mutableCopy];
    //NSMutableDictionary* EXIFDictionary = 
[[metadataAsMutable 
objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
    NSMutableDictionary *EXIFDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyExifDictionary]mutableCopy];
    NSMutableDictionary *GPSDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyGPSDictionary]mutableCopy];
    NSMutableDictionary *RAWDictionary = 
[[metadataAsMutable objectForKey:(NSString 
*)kCGImagePropertyRawDictionary]mutableCopy];

    if(!EXIFDictionary)
    EXIFDictionary = [[NSMutableDictionary dictionary] 
init];

    if(!GPSDictionary)
    GPSDictionary = [[NSMutableDictionary dictionary] 
init];

    if(!RAWDictionary)
    RAWDictionary = [[NSMutableDictionary dictionary] 
init];

    //Add the modified Data back into the image’s metadata
    [self.metadata setObject:EXIFDictionary 
forKey:(NSString *)kCGImagePropertyExifDictionary];
    [self.metadata setObject:GPSDictionary forKey:(NSString 
*)kCGImagePropertyGPSDictionary];
    [self.metadata setObject:RAWDictionary forKey:(NSString 
*)kCGImagePropertyRawDictionary];

    //NSLog(@"enter gpsdictionary %@", GPSDictionary);
    //NSLog(@"enter exifdictionary %@", EXIFDictionary);
    //NSLog(@"enter rawdictionary %@", RAWDictionary);

    //NSLog(@"enter self.metadata %@", self.metadata);
    if (self.metadata) {
    //this will be the data CGImageDestinationRef will 
write into
    NSMutableData *newImageData = [NSMutableData data];

    CGImageSourceRef sourceImage = 
CGImageSourceCreateWithData((__bridge CFDataRef)self.data, NULL);
    CFStringRef sourceType = 
CGImageSourceGetType(sourceImage);

    CGImageDestinationRef destinationImage = 
CGImageDestinationCreateWithData((__bridge CFMutableDataRef)newImageData, 
sourceType, 1, NULL);
    
CGImageDestinationAddImageFromSource(destinationImage, sourceImage, 0, 
(__bridge CFDictionaryRef)self.metadata);
    CGImageDestinationFinalize(destinationImage);