'Clean possible bad Image data.
Try to load EXIF data from image. If that fails, remove EXIF
data by re-saving the image. Related bug 919736.'

def clean_photo(self):

    photo = self.cleaned_data['photo']
    if (photo and isinstance(photo, UploadedFile)):
        image = Image.open(photo.file)
        try:
            image._get_exif()
        except (AttributeError, IOError, KeyError, IndexError):
            cleaned_photo = StringIO()
            if (image.mode != 'RGB'):
                image = image.convert('RGB')
            image.save(cleaned_photo, format='JPEG', quality=95)
            photo.file = cleaned_photo
            photo.size = cleaned_photo.tell()
    return photo
