Convert HEIF photos to JPEG for upload to the backend

I support the application for uploading photos from iPhone to the server service. This service does not currently support the new HEIF format, so is there a way for the photo framework to convert the photo data to jpeg?

I am using PHImageManager.requestImageData (for: options: resultHandler :) to retrieve a Data object from an image, which I then upload to the REST API.

+4
source share
1 answer

(new solution, the previous one did not save EXIF โ€‹โ€‹information)

JPEG, EXIF, CIImage HEIF CIContext.jpegRepresentation(: jpeg- Dataโ€‹โ€‹p >

let imageManager = PHImageManager.default()
var photo : PHAsset
var options : PHImageRequestOptions

imageManager.requestImageData(for: photo, options: options, resultHandler: {
                imageData,dataUTI,orientation,info in
let ciImage = CIImage(data: imageData!)
if #available(iOS 10.0, *) {
    data = CIContext().jpegRepresentation(of: ciImage!, colorSpace: CGColorSpaceCreateDeviceRGB())!
    // upload image data
}
+3

Source: https://habr.com/ru/post/1687523/


All Articles