オクラホマから保存して削除フックを使用する必要があり、そのコードは(PIL thumbnail is rotating my image?からコピーしたオートローテーションコード)である、ように見えます:
from PIL import Image, ExifTags
def autorotate(path):
""" This function autorotates a picture """
image = Image.open(path)
if hasattr(image, '_getexif'): # only present in JPEGs
orientation = None
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation] == 'Orientation':
break
e = image._getexif() # returns None if no EXIF data
if e is not None:
exif = dict(e.items())
orientation = exif[orientation]
if orientation == 3:
image = image.transpose(Image.ROTATE_180)
elif orientation == 6:
image = image.transpose(Image.ROTATE_270)
elif orientation == 8:
image = image.transpose(Image.ROTATE_90)
image.save(path)
class ReceivedDataList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
filter_backends = (filters.DjangoFilterBackend,)
filter_class = UserFilter
def perform_create(self, serializer):
instance = serializer.save()
autorotate(instance.photo.file.name)