Skip to content

Commit 9118654

Browse files
authored
Merge pull request #849 from techinpark/feature/exif
Extract EXIF-only metadata for image cropping
2 parents cf2d9c2 + 582010f commit 9118654

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Source/Helpers/Extensions/PHCachingImageManager+Extensions.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ extension PHCachingImageManager {
3939
height: targetSize.height)
4040
if let imageRef = image.cgImage?.cropping(to: scaledCropRect) {
4141
let croppedImage = UIImage(cgImage: imageRef)
42-
let exifs = self.metadataForImageData(data: data)
42+
let exifs = self.exifDataForImageData(data: data)
4343
callback(croppedImage, exifs)
4444
}
4545
}
4646
}
4747
}
4848

49-
private func metadataForImageData(data: Data) -> [String: Any] {
49+
private func exifDataForImageData(data: Data) -> [String: Any] {
50+
var exifData: [String: Any] = [:]
51+
5052
if let imageSource = CGImageSourceCreateWithData(data as CFData, nil),
51-
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil),
52-
let metaData = imageProperties as? [String: Any] {
53-
return metaData
53+
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil),
54+
let propertiesDict = imageProperties as? [String: Any],
55+
let exifDict = propertiesDict[kCGImagePropertyExifDictionary as String] as? [String: Any] {
56+
exifData = exifDict
5457
}
55-
return [:]
58+
59+
return exifData
5660
}
5761

5862
func fetchPreviewFor(video asset: PHAsset, callback: @escaping (UIImage) -> Void) {

0 commit comments

Comments
 (0)