Convert HEIC images to JPEG before upload

Fixes #60
This commit is contained in:
Shadowfacts 2019-12-31 16:41:56 -05:00
parent 6ef643e374
commit b2956b6118
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 3 deletions

View File

@ -493,9 +493,19 @@ class ComposeViewController: UIViewController {
options.resizeMode = .none options.resizeMode = .none
options.isNetworkAccessAllowed = true options.isNetworkAccessAllowed = true
PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, dataUTI, orientation, info) in PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, dataUTI, orientation, info) in
guard let data = data, let dataUTI = dataUTI else { fatalError() } guard var data = data, let dataUTI = dataUTI else { fatalError() }
let mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType)!.takeRetainedValue() as String 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() self.postProgressView.step()