Capture Filtered Image with GPUImage and Save to Photo Library with Metadata

379 views Asked by At

I am developing a simple came app for iOS 10. I need to live filter a camera feed, and then capture and save the filtered image.

Using GPUImage, I have been able to setup the live feed and the image capture using GPUImageStillCamera. I am also using the PHPhotoLibrary APIs:

func saveToPhotoLibrary(data: Data, completion: @escaping (PHAsset?) -> ()) {
    var assetIdentifier: String?
    PHPhotoLibrary.requestAuthorization { (status) in
      if status == .authorized {
        PHPhotoLibrary.shared().performChanges({
          let creationRequest = PHAssetCreationRequest.forAsset()
          let placeholder = creationRequest.placeholderForCreatedAsset

          creationRequest.addResource(with: .photo, data: data, options: .none)

          assetIdentifier = placeholder?.localIdentifier

        }, completionHandler: { (success, error) in
          if let error = error {
            print("There was an error saving to the photo library: \(error)")
          }
          var asset: PHAsset? = .none
          if let assetIdentifier = assetIdentifier {
            asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetIdentifier], options: .none).firstObject
          }
          completion(asset)
        })
      } else {
        print("Need authorisation to write to the photo library")
        completion(.none)
      }
    }
  }

The problem is that when this image gets saved, the metadata (such as camera and device information) is missing. How can I save this image with the filter, yet still retain the image metadata?

0

There are 0 answers