Reputation: 1552
Situation: For an upload; I need a client side check if an image is a 360° image from a camera like the Theta S or Gear 360. This should be fairly easily done by checking the XMP metadata.
However, ImageIO seems to ignore the XMP metadata, if you run the example below, there is no XMP-entry in the data ImageIO returns.
Swift 3:
import ImageIO
let url = URL(fileURLWithPath: filePath)
let imageData:Data = try! Data(contentsOf: url)
if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil),
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [AnyHashable:Any]
{
print(imageProperties) // no xmp metadata?
}
Is there any way I can substract the XMP-xml from the images NSData?
Upvotes: 1
Views: 1416
Reputation: 10730
If just checking for one specific value in the XMP metadata, instead of enumerating, you can also search for it like this:
guard let source = CGImageSourceCreateWithData(self as NSData, nil) else { return }
guard let metadata = CGImageSourceCopyMetadataAtIndex(source, 0, nil) else { return }
let tag = CGImageMetadataCopyTagWithPath(metadata, nil, "GPano:ProjectionType" as NSString)
Upvotes: 1
Reputation: 1552
I found you can access this information with CGImageSourceCopyMetadataAtIndex
.
Rough code example:
Swift 3:
if let imageSource = CGImageSourceCreateWithData(nsData as CFData, nil),
let imageProperties = CGImageSourceCopyMetadataAtIndex(imageSource, 0, nil) {
var result:String = ""
CGImageMetadataEnumerateTagsUsingBlock(imageProperties, nil, nil, { (key, tag) -> Bool in
let tagString:NSString = CGImageMetadataTagCopyName(tag) as! NSString
if tagString == "ProjectionType" {
result = CGImageMetadataTagCopyValue(tag) as! NSString
return false
}
return true
})
print(result) //equirectangular
}
Upvotes: 2