You can also determine the image type without relying on the path extension with CGImageSource (part of the ImageIO framework).
The following example uses a file URL, but you can also create an image source from a CFDataRef.
CFStringRef typeOfImageAtURL(NSURL *imageURL) {
const void * keys[] = { kCGImageSourceShouldCache };
const void * values[] = { kCFBooleanFalse };
CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, NULL, NULL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, options);
CFStringRef imageType = CGImageSourceGetType(imageSource);
CFRelease(options);
CFRelease(imageSource);
return imageType;
}
The return value will be a constant that you can compare with the uniform type identifier values declared in CoreServices/MobileCoreServices (e.g., kUTTypeJPEG, kUTTypeGIF, etc).
The icing on the cake: you can pass in an optional "hint" UTI if you have reason to anticipate one file type or another. Combine this approach with Bavarious' and you'll have a lean, mean image format detection machine.