Sometimes images picked from the photo album with UIImagePickerController
are cropped differently than how the user wants to crops it. This happens in approx. 1 of 50 image uploads.
When it happens the images are always cropped to a part of the image from the top left corner. Here is an example image with (1) showing in the red rectangle what the user supposedly selects to crop and (2) what image ends up on the server.
The selection in (1) is assumptive because it's unknown how the users exactly positions the crop and it was not possible to reproduce this incorrect cropping yet. It has only been observed with the live app. Some users tried to upload the same image multiple times always with the same incorrect crop and eventually complained, so it's not that users deliberately crop images like this.
Some users tried to upload different images and all of them were incorrectly cropped.
Here is the code (simplified but nothing more happens to the image):
class ImagePicker {
private let imagePicker = UIImagePickerController()
func showPicker() {
imagePicker.sourceType = .PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = true
imagePicker.delegate = delegate
imagePicker.modalPresentationStyle = .OverFullScreen
parentViewController.presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
uploadImage(image)
}
picker.dismissViewControllerAnimated(true, completion: nil)
}
func uploadImage(image: UIImage) {
let imageData = UIImageJPEGRepresentation(image, 0.75)!
let imageFile = PFFile(name: "image.png", data: imageData)
// Upload to Open Source Parse Server which stores the image in an Amazon S3 bucket.
let imageObject = PFObject(className: "ImageClass")
imageObject(imageFile, forKey: "imageFile")
imageObject.saveInBackground()
}
}
Does anyone know why this happens?
Update:
I was able to reproduce the issue on an iPad, I will update here what the outcome was.
Update:
The issue occurred only on iPads so it is presumably related to a bug in the UIImagePickerViewController
when cropping an image.