Normalize uploaded image rotation based on EXIF data

Extension of #6560. I wanted to add test cases, but ended up finding a few bugs and ran out of time.