Skip to content

Instantly share code, notes, and snippets.

@ymoussaba
Created February 27, 2016 23:09
Show Gist options
  • Select an option

  • Save ymoussaba/83e90d95085d37ed4275 to your computer and use it in GitHub Desktop.

Select an option

Save ymoussaba/83e90d95085d37ed4275 to your computer and use it in GitHub Desktop.

Revisions

  1. Vadim Shpakovski revised this gist Feb 5, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Image.m
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,10 @@ - (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
    CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
    if (source) {
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImageSourceShouldCache];
    NSDictionary *properties = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, (CFDictionaryRef)options);
    CFDictionaryRef properties = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, (CFDictionaryRef)options);
    if (properties) {
    NSNumber *width = [properties objectForKey:(NSString *)kCGImagePropertyPixelWidth];
    NSNumber *height = [properties objectForKey:(NSString *)kCGImagePropertyPixelHeight];
    NSNumber *width = [(NSDictionary *)properties objectForKey:(NSString *)kCGImagePropertyPixelWidth];
    NSNumber *height = [(NSDictionary *)properties objectForKey:(NSString *)kCGImagePropertyPixelHeight];
    if ((width != nil) && (height != nil))
    imageSize = CGSizeMake(width.floatValue, height.floatValue);
    CFRelease(properties);
  2. Vadim Shpakovski revised this gist Feb 5, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Image.m
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    // This method requires ImageIO.framework
    #import <ImageIO/ImageIO.h>

    - (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
    {
    // With CGImageSource we avoid loading the whole image into memory
  3. Vadim Shpakovski renamed this gist Feb 5, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. Vadim Shpakovski revised this gist Feb 5, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,8 @@
    if (properties) {
    NSNumber *width = [properties objectForKey:(NSString *)kCGImagePropertyPixelWidth];
    NSNumber *height = [properties objectForKey:(NSString *)kCGImagePropertyPixelHeight];
    if ((width != nil) && (height != nil)) {
    if ((width != nil) && (height != nil))
    imageSize = CGSizeMake(width.floatValue, height.floatValue);
    }
    CFRelease(properties);
    }
    CFRelease(source);
  5. Vadim Shpakovski created this gist Feb 5, 2012.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    - (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
    {
    // With CGImageSource we avoid loading the whole image into memory
    CGSize imageSize = CGSizeZero;
    CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
    if (source) {
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImageSourceShouldCache];
    NSDictionary *properties = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, (CFDictionaryRef)options);
    if (properties) {
    NSNumber *width = [properties objectForKey:(NSString *)kCGImagePropertyPixelWidth];
    NSNumber *height = [properties objectForKey:(NSString *)kCGImagePropertyPixelHeight];
    if ((width != nil) && (height != nil)) {
    imageSize = CGSizeMake(width.floatValue, height.floatValue);
    }
    CFRelease(properties);
    }
    CFRelease(source);
    }
    return imageSize;
    }