import subprocess
from datetime import datetime, time, timedelta
+import piexif
import taggit.utils
from django.utils.encoding import force_str
from PIL import Image
if not os.path.exists(image_path):
return
image = Image.open(image_path)
+
+ kwargs = {}
+ save_image = False
+
+ if 'exif' in image.info:
+ exif_dict = piexif.load(image.info['exif'])
+ if 0x9208 in exif_dict.get('Exif', {}):
+ # remove LightSource exif data as it's corrupt on some motorola phones
+ del exif_dict['Exif'][0x9208]
+ kwargs = {'exif': piexif.dump(exif_dict)}
+ save_image = True
+
if max(image.size) > 1400:
# no sense storing images that large
factor = 1400.0 / max(image.size)
# make sure png files are always RGB
# (it happened cmyk jpeg files were uploaded with a .png extension and that would fail)
image = image.convert('RGB')
- image.save(image_path)
+ save_image = True
+
+ if save_image:
+ image.save(image_path, **kwargs)
def whatsonair(now=None):