Skip to content

Instantly share code, notes, and snippets.

@elpsk
Last active September 1, 2016 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elpsk/129fa2848840781a94623e7a366e9c74 to your computer and use it in GitHub Desktop.
Save elpsk/129fa2848840781a94623e7a366e9c74 to your computer and use it in GitHub Desktop.
Get contentTypeForImageData from image byte header
- (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"jpeg";
case 0x89:
return @"png";
case 0x47:
return @"gif";
case 0x49:
case 0x4D:
return @"tiff";
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment