How to get image metadata in ios How to get image metadata in ios ios ios

How to get image metadata in ios


CGImageSourceRef source = CGImageSourceCreateWithURL( (CFURLRef) aUrl, NULL);CGImageSourceRef source = CGImageSourceCreateWithData( (CFDataRef) theData, NULL);NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL));CFRelease(source);

Check the dictionary contents here.


Here is code, to get meta data from an image path:

NSData *imagedata = [NSData dataWithContentsOfFile:imagePath];CGImageSourceRef source = CGImageSourceCreateWithData((CFMutableDataRef)imagedata, NULL);NSDictionary *metadata = [(NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL)autorelease];

Or, if using swift 4.0:

var imagedata = Data(contentsOfFile: imagePath) var source: CGImageSourceRef = CGImageSourceCreateWithData((imagedata as? CFMutableDataRef), nil) var metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [AnyHashable: Any]


swift 4

static func imageDataProperties(_ imageData: Data) -> NSDictionary? {    if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil)    {      if let dictionary = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) {        return dictionary      }    }    return nil  }