Projet

Général

Profil

0001-misc-adapt-thumbnail-orientation-using-EXIF-metadata.patch

Frédéric Péters, 02 février 2019 20:24

Télécharger (1,79 ko)

Voir les différences:

Subject: [PATCH] misc: adapt thumbnail orientation using EXIF metadata
 (#30235)

 wcs/qommon/misc.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
wcs/qommon/misc.py
60 60
    HAS_GM = False
61 61

  
62 62

  
63
EXIF_ORIENTATION = 0x0112
64

  
63 65
class ThumbnailError(Exception):
64 66
    pass
65 67

  
......
594 596

  
595 597
    try:
596 598
        image = Image.open(fp)
599
        try:
600
            exif = image._getexif()
601
        except:
602
            exif = None
603

  
604
        if exif:
605
            # orientation code from sorl.thumbnail (engines/pil_engine.py)
606
            orientation = exif.get(EXIF_ORIENTATION)
607

  
608
            if orientation == 2:
609
                image = image.transpose(Image.FLIP_LEFT_RIGHT)
610
            elif orientation == 3:
611
                image = image.rotate(180)
612
            elif orientation == 4:
613
                image = image.transpose(Image.FLIP_TOP_BOTTOM)
614
            elif orientation == 5:
615
                image = image.rotate(-90, expand=1).transpose(Image.FLIP_LEFT_RIGHT)
616
            elif orientation == 6:
617
                image = image.rotate(-90, expand=1)
618
            elif orientation == 7:
619
                image = image.rotate(90, expand=1).transpose(Image.FLIP_LEFT_RIGHT)
620
            elif orientation == 8:
621
                image = image.rotate(90, expand=1)
622

  
597 623
        image.thumbnail((500, 300))
598 624
        image_thumb_fp = StringIO()
599 625
        image.save(image_thumb_fp, "PNG")
600
-