django-avatar: cant save thumbnail

Posted by Znack on Stack Overflow See other posts from Stack Overflow or by Znack
Published on 2014-06-07T13:11:44Z Indexed on 2014/06/08 3:25 UTC
Read the original article Hit count: 153

Filed under:
|

I'm use django-avatar app and can't make it to save thumbnails. The original image save normally in my media dir. Using the step execution showed that error occurred here

image.save(thumb, settings.AVATAR_THUMB_FORMAT, quality=quality)

I found this line in create_thumbnail:

def create_thumbnail(self, size, quality=None):
    # invalidate the cache of the thumbnail with the given size first
    invalidate_cache(self.user, size)
    try:
        orig = self.avatar.storage.open(self.avatar.name, 'rb')
        image = Image.open(orig)
        quality = quality or settings.AVATAR_THUMB_QUALITY
        w, h = image.size
        if w != size or h != size:
            if w > h:
                diff = int((w - h) / 2)
                image = image.crop((diff, 0, w - diff, h))
            else:
                diff = int((h - w) / 2)
                image = image.crop((0, diff, w, h - diff))
            if image.mode != "RGB":
                image = image.convert("RGB")
            image = image.resize((size, size), settings.AVATAR_RESIZE_METHOD)
            thumb = six.BytesIO()
            image.save(thumb, settings.AVATAR_THUMB_FORMAT, quality=quality)
            thumb_file = ContentFile(thumb.getvalue())
        else:
            thumb_file = File(orig)
        thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)
    except IOError:
        return  # What should we do here?  Render a "sorry, didn't work" img?

maybe all I need is just some library? Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about django