MessageKit / MessageInputBar

A powerful InputAccessoryView ideal for messaging applications
MIT License
64 stars 44 forks source link

Images pasted into InputTextView have incorrect orientation #23

Closed nfogg closed 5 years ago

nfogg commented 5 years ago

I am having difficulty handling image orientations correctly in the InputTextView. Images attached from the Photos library or from the devices camera can appear sideways or upside down in the InputTextView. This is happening in MessageInputBar version 0.4.1.

I am attaching images from a UIImagePickerController with the following code:

extension ConversationViewController: UIImagePickerControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            messageInputBar.inputTextView.pasteImageInTextContainer(with: image)
            dismiss(animated: true, completion: nil)
        }
    }
}

This problem can be reproduced using the ChatExample app in the simulator (iOS 12.1) with the following steps:

  1. From the simulator's Photos app, copy the flowers photo to the clipboard
  2. In the ChatExample app, paste the clipboard contents into the InputTextView

Note that the pasted image is upside down.

image image
nathantannar4 commented 5 years ago

Hmm, I just tried on my phone and it's the correct orientation. Could be a simulator issue.

Sent with GitHawk

tanujkumar1640 commented 5 years ago

Change this textAttachment.image = UIImage(cgImage: cgImage, scale: scale, orientation: .up) to textAttachment.image = UIImage(cgImage: cgImage, scale: scale, orientation: image.imageOrientation)

nfogg commented 5 years ago

Thanks @1640, your suggestion worked a treat!

@nathantannar4 I've created PR https://github.com/MessageKit/MessageInputBar/pull/25 with this small fix.

nfogg commented 5 years ago

Closing now that PR #25 has been merged.