Created
August 2, 2011 18:36
-
-
Save thekarladam/1120857 to your computer and use it in GitHub Desktop.
Extract a jpeg photo from your dslocal user file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh yea, for those not familiar with gcc command line:
gcc jpg.m -framework Foundation -framework AppKit -o jpg.a