Why photos end up sideways in the first place
Phones and cameras record which way you were holding them in an EXIF orientation tag rather than physically rotating the pixels. Most apps honour that tag, but plenty of upload forms, printers, and older programs ignore it, which is why a photo that looked fine on your phone suddenly appears rotated elsewhere. Rotating the actual pixels here produces a file that displays correctly everywhere, regardless of whether the reader understands EXIF.