Mercurial > public > sg101
comparison core/image_uploader.py @ 837:234726f5a47a
For issue #74, re-orient uploaded images if necessary.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 04 Oct 2014 13:43:22 -0500 |
parents | df2799f725d8 |
children | ee47122d6277 |
comparison
equal
deleted
inserted
replaced
836:1e44691932b2 | 837:234726f5a47a |
---|---|
10 import uuid | 10 import uuid |
11 | 11 |
12 from PIL import Image | 12 from PIL import Image |
13 | 13 |
14 from core.functions import temp_open | 14 from core.functions import temp_open |
15 from core.image import orient_image | |
15 | 16 |
16 | 17 |
17 logger = logging.getLogger(__name__) | 18 logger = logging.getLogger(__name__) |
18 | 19 |
19 | 20 |
61 with temp_open(temp_name, 'wb') as temp_file: | 62 with temp_open(temp_name, 'wb') as temp_file: |
62 for chunk in fp.chunks(): | 63 for chunk in fp.chunks(): |
63 temp_file.write(chunk) | 64 temp_file.write(chunk) |
64 temp_file.close() | 65 temp_file.close() |
65 | 66 |
67 # Re-orient if necessary | |
68 image = Image.open(temp_name) | |
69 changed, image = orient_image(image) | |
70 if changed: | |
71 image.save(temp_name) | |
72 | |
66 # Resize image if necessary | 73 # Resize image if necessary |
67 if new_size: | 74 if new_size: |
68 image = Image.open(temp_name) | 75 image = Image.open(temp_name) |
69 if image.size > new_size: | 76 if image.size > new_size: |
70 logger.debug('Resizing from {} to {}'.format(image.size, new_size)) | 77 logger.debug('Resizing from {} to {}'.format(image.size, new_size)) |