Skip to content

Instantly share code, notes, and snippets.

@pelish8
Created January 7, 2015 18:19
Show Gist options
  • Select an option

  • Save pelish8/ed8ed7d23e34b5d2ba40 to your computer and use it in GitHub Desktop.

Select an option

Save pelish8/ed8ed7d23e34b5d2ba40 to your computer and use it in GitHub Desktop.

Revisions

  1. pelish8 created this gist Jan 7, 2015.
    17 changes: 17 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    + (NSString *)contentTypeForImageData:(NSData *)data {
    uint8_t c;
    [data getBytes:&c length:1];

    switch (c) {
    case 0xFF:
    return @"image/jpeg";
    case 0x89:
    return @"image/png";
    case 0x47:
    return @"image/gif";
    case 0x49:
    case 0x4D:
    return @"image/tiff";
    }
    return nil;
    }