Skip to content

Commit eb5fe28

Browse files
committed
Write EXIF metadata to camera images
* When taking a picture from the camera, grab the exif data and write that into the image * For FIC thumbnails make sure the orientation is passed to the thum so that it is oriented correctly. fixes #44
1 parent c83dc55 commit eb5fe28

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

MAGE.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@
10211021
ORGANIZATIONNAME = "National Geospatial Intelligence Agency";
10221022
TargetAttributes = {
10231023
F7A94D6518AD9CB000CB9EE0 = {
1024-
DevelopmentTeam = ZL8G5D9G2H;
1024+
DevelopmentTeam = A8EK924J35;
10251025
};
10261026
};
10271027
};
@@ -1382,7 +1382,7 @@
13821382
INFOPLIST_FILE = "Mage/MAGE-Info.plist";
13831383
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
13841384
OTHER_LDFLAGS = "$(inherited)";
1385-
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.mage;
1385+
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.giat.MAGE;
13861386
PRODUCT_NAME = MAGE;
13871387
PROVISIONING_PROFILE = "";
13881388
WRAPPER_EXTENSION = app;
@@ -1404,7 +1404,7 @@
14041404
INFOPLIST_FILE = "Mage/MAGE-Info.plist";
14051405
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
14061406
OTHER_LDFLAGS = "$(inherited)";
1407-
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.mage;
1407+
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.giat.MAGE;
14081408
PRODUCT_NAME = MAGE;
14091409
PROVISIONING_PROFILE = "";
14101410
WRAPPER_EXTENSION = app;

Mage/Attachment+FICAttachment.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ - (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatNa
6363
}
6464

6565
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
66-
imageToUse = [UIImage imageWithCGImage:imageRef];
67-
CGImageRelease(imageRef);
66+
imageToUse = [UIImage imageWithCGImage:imageRef scale:image.scale orientation:[image imageOrientation]];
67+
68+
CGImageRelease(imageRef);
6869

6970
[imageToUse drawInRect:contextBounds];
7071
UIGraphicsPopContext();

Mage/MAGE-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<key>CFBundleSignature</key>
3737
<string>????</string>
3838
<key>CFBundleVersion</key>
39-
<string>20160521</string>
39+
<string>20160522</string>
4040
<key>LSApplicationCategoryType</key>
4141
<string></string>
4242
<key>LSRequiresIPhoneOS</key>

Mage/ObservationEditViewController.m

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "AttachmentSelectionDelegate.h"
2121
#import <Server+helper.h>
2222
#import <Event+helper.h>
23+
#import <ImageIO/ImageIO.h>
2324
#import "ObservationEditTextFieldTableViewCell.h"
2425

2526
@interface ObservationEditViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate, AudioRecordingDelegate, AttachmentSelectionDelegate>
@@ -193,6 +194,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
193194
}
194195
} else {
195196
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
197+
NSMutableDictionary *imageMetadata = [[info objectForKey:UIImagePickerControllerMediaMetadata] mutableCopy];
196198

197199
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
198200
[dateFormatter setDateFormat:@"yyyymmdd_HHmmss"];
@@ -213,12 +215,34 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
213215
NSLog(@"Error creating directory path: %@", [error localizedDescription]);
214216
}
215217

216-
NSData *imageData = UIImagePNGRepresentation(chosenImage);
217-
BOOL success = [imageData writeToFile:fileToWriteTo atomically:NO];
218+
NSData *imageData = UIImageJPEGRepresentation(chosenImage, 1.0f);
219+
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) imageData, NULL);
220+
CFStringRef UTI = CGImageSourceGetType(source);
221+
NSMutableData *destinationData = [NSMutableData data];
222+
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) destinationData, UTI, 1, NULL);
223+
224+
if (!destinationData) {
225+
NSLog(@"Error: Could not create image destination");
226+
}
227+
228+
// add the image contained in the image source to the destination, overidding the old metadata with our modified metadata
229+
CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef) imageMetadata);
230+
BOOL success = NO;
231+
success = CGImageDestinationFinalize(destination);
232+
233+
success = [destinationData writeToFile:fileToWriteTo atomically:NO];
234+
235+
if (!success) {
236+
NSLog(@"Error: Could not create data from image destination");
237+
}
238+
239+
CFRelease(destination);
240+
CFRelease(source);
241+
218242
NSLog(@"successfully wrote file %d", success);
219243

220244
NSMutableDictionary *attachmentJson = [NSMutableDictionary dictionary];
221-
[attachmentJson setValue:@"image/png" forKey:@"contentType"];
245+
[attachmentJson setValue:@"image/jpeg" forKey:@"contentType"];
222246
[attachmentJson setValue:fileToWriteTo forKey:@"localPath"];
223247
[attachmentJson setValue:[NSString stringWithFormat: @"MAGE_%@.png", [dateFormatter stringFromDate: [NSDate date]]] forKey:@"name"];
224248
[attachmentJson setValue:[NSNumber numberWithBool:YES] forKey:@"dirty"];

0 commit comments

Comments
 (0)