So far CSS: image-orientation:from-image; more universally supported, we make a server-side solution with python. That is the essence of this. You check the exif data for orientation, then rotate the image accordingly and save.
We prefer this solution over client solutions, as it does not require downloading third-party libraries on the client side, and this operation should happen only once when downloading a file.
if fileType == "image": exifToolCommand = "exiftool -j '%s'" % filePath exif = json.loads(subprocess.check_output(shlex.split(exifToolCommand), stderr=subprocess.PIPE)) if 'Orientation' in exif[0]: findDegrees, = re.compile("([0-9]+)").search(exif[0]['Orientation']).groups() if findDegrees: rotateDegrees = int(findDegrees) if 'CW' in exif[0]['Orientation'] and 'CCW' not in exif[0]['Orientation']: rotateDegrees = rotateDegrees * -1 # rotate image img = Image.open(filePath) img2 = img.rotate(rotateDegrees) img2.save(filePath)
deweydb Dec 02 '17 at 0:09 2017-12-02 00:09
source share