diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 51751f09af..c72f4bf9ff 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -493,10 +493,20 @@ class ComposeViewController: UIViewController { options.resizeMode = .none options.isNetworkAccessAllowed = true PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, dataUTI, orientation, info) in - guard let data = data, let dataUTI = dataUTI else { fatalError() } - - let mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType)!.takeRetainedValue() as String + guard var data = data, let dataUTI = dataUTI else { fatalError() } + let mimeType: String + if dataUTI == "public.heic" { + // neither Mastodon nor Pleroma handles HEIC well, so convert to JPEG + let image = CIImage(data: data)! + let context = CIContext() + let colorSpace = image.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)! + data = context.jpegRepresentation(of: image, colorSpace: colorSpace, options: [:])! + mimeType = "image/jpeg" + } else { + mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType)!.takeRetainedValue() as String + } + self.postProgressView.step() let request = MastodonController.client.upload(attachment: FormAttachment(mimeType: mimeType, data: data, fileName: "file"), description: description)