Skip to content

Instantly share code, notes, and snippets.

@thekarladam
Created August 2, 2011 18:36
Show Gist options
  • Save thekarladam/1120857 to your computer and use it in GitHub Desktop.
Save thekarladam/1120857 to your computer and use it in GitHub Desktop.
Extract a jpeg photo from your dslocal user file
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *sourceFile = [NSString stringWithCString:(const char *)argv[1] encoding:NSUTF8StringEncoding];
NSData *fileData = [NSData dataWithContentsOfFile:[sourceFile stringByExpandingTildeInPath]];
NSDictionary *plist = [NSPropertyListSerialization propertyListWithData:fileData options:0 format:NULL error:NULL];
NSArray *photos = [plist objectForKey:@"jpegphoto"];
NSData *imageData = [photos objectAtIndex:0];
NSImage *jpegImage = [[NSImage alloc] initWithData:imageData];
NSBitmapImageRep *imgRep = [[jpegImage representations] objectAtIndex:0];
NSData *data = [imgRep representationUsingType: NSJPEGFileType properties:nil];
[data writeToFile:[@"~/img.jpg" stringByExpandingTildeInPath] atomically:NO];
[pool release];
return EXIT_SUCCESS;
}
@thekarladam
Copy link
Author

oh yea, for those not familiar with gcc command line:
gcc jpg.m -framework Foundation -framework AppKit -o jpg.a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment