Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from io import BytesIO
- from django.core.files.uploadedfile import InMemoryUploadedFile
- from sys import getsizeof
- image = self.cleaned_data.get("image")
- if not image:
- image = ''
- return image
- size = (145,145)
- im = Image.open(image)
- output = BytesIO()
- im.thumbnail(size)
- im.save(output, format='JPEG', quality=100)
- output.seek(0)
- image = InMemoryUploadedFile(output,'ImageField', "%s.jpg" %image.name.split('.')[0], 'image/jpeg', getsizeof(output), None)
- return image
Add Comment
Please, Sign In to add comment