Add rotate thumbnail
This commit is contained in:
parent
d679bfaea9
commit
149890f2eb
2 changed files with 14 additions and 2 deletions
|
|
@ -36,4 +36,4 @@ echo "---> 'cp test_data/index.html data/'"
|
||||||
cp test_data/index.html data/
|
cp test_data/index.html data/
|
||||||
|
|
||||||
echo "---> 'python distribusi/test.py -d ./data/'"
|
echo "---> 'python distribusi/test.py -d ./data/'"
|
||||||
python distribusi/test.py -d ./data/
|
python distribusi/test.py -t -d ./data/
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import subprocess
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import magic
|
import magic
|
||||||
from PIL import Image
|
from PIL import Image, ExifTags
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
from distribusi.page_template import html_footer, html_head
|
from distribusi.page_template import html_footer, html_head
|
||||||
|
|
@ -39,8 +39,20 @@ def thumbnail(image, name, args):
|
||||||
try:
|
try:
|
||||||
size = (450, 450)
|
size = (450, 450)
|
||||||
im = Image.open(image)
|
im = Image.open(image)
|
||||||
|
|
||||||
|
for orientation in ExifTags.TAGS.keys():
|
||||||
|
if ExifTags.TAGS[orientation] == 'Orientation':
|
||||||
|
break
|
||||||
|
exif = im._getexif()
|
||||||
im.thumbnail(size)
|
im.thumbnail(size)
|
||||||
|
|
||||||
|
if exif[orientation] == 3:
|
||||||
|
im = im.rotate(180, expand=True)
|
||||||
|
elif exif[orientation] == 6:
|
||||||
|
im = im.rotate(270, expand=True)
|
||||||
|
elif exif[orientation] == 8:
|
||||||
|
im = im.rotate(90, expand=True)
|
||||||
|
|
||||||
if (im.mode == 'RGBA'):
|
if (im.mode == 'RGBA'):
|
||||||
bg = Image.new('RGBA', im.size, (255,255,255))
|
bg = Image.new('RGBA', im.size, (255,255,255))
|
||||||
composite = Image.alpha_composite(bg, im)
|
composite = Image.alpha_composite(bg, im)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue