Image exif_transpose not working with Pillow 7

I also just ran into this bug so here are a few things I've found:

Here's a link to a relevant github issue

According to this comment, this problem only affects images with specific tags. Also this only applies to version 7, while version 6 had a different but similar issue that stopped exif_transpose from working. The comment says this wasn't fixed until version 8.1.0. I'm trying on version 9 and it appears to be fixed.

I'd recommend upgrading your version of pillow. If you're not able to do that, you could try this. I haven't tested it on pillow 7 but it looks like it may work.

    import Image, ExifTags

try :
    image=Image.open(os.path.join(path, fileName))
    for orientation in ExifTags.TAGS.keys() : 
        if ExifTags.TAGS[orientation]=='Orientation' : break 
    exif=dict(image._getexif().items())

    if   exif[orientation] == 3 : 
        image=image.rotate(180, expand=True)
    elif exif[orientation] == 6 : 
        image=image.rotate(270, expand=True)
    elif exif[orientation] == 8 : 
        image=image.rotate(90, expand=True)

    image.thumbnail((THUMB_WIDTH , THUMB_HIGHT), Image.ANTIALIAS)
    image.save(os.path.join(path,fileName))

except:
    traceback.print_exc()