Skip to content

Instantly share code, notes, and snippets.

@rentzsch
Created February 28, 2009 17:51
Show Gist options
  • Save rentzsch/72020 to your computer and use it in GitHub Desktop.
Save rentzsch/72020 to your computer and use it in GitHub Desktop.
NSURL *imgURL = [NSURL fileURLWithPath:@"/tmp/MyDocumentName.jpg"];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imgURL, NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
NSMutableDictionary *props = [[[((id)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL)) autorelease] mutableCopy] autorelease];
[props setObject:[NSNumber numberWithFloat:300.0] forKey:(id)kCGImagePropertyDPIHeight];
[props setObject:[NSNumber numberWithFloat:300.0] forKey:(id)kCGImagePropertyDPIWidth];
CGImageDestinationRef myImageDest = CGImageDestinationCreateWithURL((CFURLRef)imgURL, kUTTypeJPEG, 1, nil);
CGImageDestinationAddImage(myImageDest, imageRef, (CFDictionaryRef)props);
CGImageDestinationFinalize(myImageDest);
CGImageRelease(imageRef);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment