Resizing uploaded files in django using PIL
Posted
by
Nikunj
on Stack Overflow
See other posts from Stack Overflow
or by Nikunj
Published on 2012-06-05T04:37:20Z
Indexed on
2012/06/05
4:40 UTC
Read the original article
Hit count: 286
I am using PIL to resize an uploaded file using this method:
def resize_uploaded_image(buf):
imagefile = StringIO.StringIO(buf.read())
imageImage = Image.open(imagefile)
(width, height) = imageImage.size
(width, height) = scale_dimensions(width, height, longest_side=240)
resizedImage = imageImage.resize((width, height))
return resizedImage
I then use this method to get the resizedImage in my main view method:
image = request.FILES['avatar']
resizedImage = resize_uploaded_image(image)
content = django.core.files.File(resizedImage)
acc = Account.objects.get(account=request.user)
acc.avatar.save(image.name, content)
However, this gives me the 'read' error.
Trace:
Exception Type: AttributeError at /myapp/editAvatar Exception Value: read
Any idea how to fix this? I have been at it for hours! Thanks!
Nikunj
© Stack Overflow or respective owner