Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
Created July 10, 2017 11:51
Show Gist options
  • Select an option

  • Save mvasilkov/0cb0858b7a0d0c525740b787f61a9219 to your computer and use it in GitHub Desktop.

Select an option

Save mvasilkov/0cb0858b7a0d0c525740b787f61a9219 to your computer and use it in GitHub Desktop.

Revisions

  1. mvasilkov created this gist Jul 10, 2017.
    20 changes: 20 additions & 0 deletions foo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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()