From 744329dca2e72cd69e876a372dc7439edd5b8e50 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 19 Oct 2020 18:33:10 -0400 Subject: [PATCH] Upload photos taken from UIImagePickerController as JPEGs instead of PNGs --- Tusker/Models/CompositionAttachmentData.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tusker/Models/CompositionAttachmentData.swift b/Tusker/Models/CompositionAttachmentData.swift index b8f424a6..3f5fa6dc 100644 --- a/Tusker/Models/CompositionAttachmentData.swift +++ b/Tusker/Models/CompositionAttachmentData.swift @@ -51,7 +51,10 @@ enum CompositionAttachmentData { func getData(completion: @escaping (_ data: Data, _ mimeType: String) -> Void) { switch self { case let .image(image): - completion(image.pngData()!, "image/png") + // Export as JPEG instead of PNG, otherweise photos straight from the camera are too large + // for Mastodon in its default configuration (max of 10MB). + // The quality of 0.8 was chosen completely arbitrarily, it may need to be tuned in the future. + completion(image.jpegData(compressionQuality: 0.8)!, "image/jpeg") case let .asset(asset): if asset.mediaType == .image { let options = PHImageRequestOptions()