Upload photos taken from UIImagePickerController as JPEGs instead of PNGs

This commit is contained in:
Shadowfacts 2020-10-19 18:33:10 -04:00
parent 45ac40b125
commit 744329dca2
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 4 additions and 1 deletions

View File

@ -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()