A phone held upright doesn't rotate the pixels it saves. It stores the image in the camera sensor's orientation , often landscape, and adds an EXIF Orientation tag (value 6, for example, means "rotate 90° clockwise to display"). Photo viewers and browsers apply the tag, so the user sees an upright document. OCR and face detection read the raw pixels , so they get the document sideways : text lines run vertically and recognition quality collapses. The fix is one line with Pillow, ImageOps.exif_transpose(img) , applied before anything else touches the image. It has to come first, because re-encoding or stripping metadata before applying it loses the orientation permanently .…