Hi,
I am stuck on the interface between a PIL Image and a 
FilesystemStorage 'content' object.

I can: img = Image.open(content)
But how do I pass 'img' back to Django for saving?

My short class is pasted at end. The problem reported stems from the line:
name=super(CustomImageStorage,self).save(name,img)

It barfs in PIL saying:
Exception Type:         AttributeError
Exception Value:        

chunks

Exception Location:     /usr/lib/python2.5/site-packages/PIL/Image.py in 
__getattr__, line 493


I dir() the content and img objects and sure enough, img has no 'chunks' 
attribute.

Anyway, I can always use img.save(path) but wanted to keep the image in memory 
and not touch ground with it.

Any ideas?
\d

Code:
class CustomImageStorage( FileSystemStorage ):
        def __init__(self, location, base_url, 
makethumbs=False,dropshadow=None):
                
super(CustomImageStorage,self).__init__(location=location,base_url=base_url)
                self._makethumbs = makethumbs
                self._dropshadow = dropshadow

        def get_available_name( self, name ):
                self.delete(name)
                return name

        def save(self, name, content ):
                content.seek(0)
                img = Image.open(content)
                if self._dropshadow:
                        img = dropShadow(img, background = 
self._dropshadow['background'],
                                        shadow = self._dropshadow['shadow'], 
                                        offset = self._dropshadow['offset'],
                                        iterations = 
self._dropshadow['iterations'],
                                        border = self._dropshadow['border']
                                        )
                if self._makethumbs:
                        try:
                                thumb = img.copy()
                                fpaf = self.thumbPath(name) 
                                thumb.thumbnail((64,64),Image.ANTIALIAS)
                                thumb.save( fpaf )
                        except:
                                pass # some damn error.
                img.seek(0) # Random attempt at a fix
                name = super( CustomImageStorage,self).save(name,img) # was 
content
                return name

        def delete( self, name):
                super(CustomImageStorage,self).delete(name)
                if self._makethumbs:
                        # Now to remove the thumbnail too.
                        try:
                                fpaf = self.thumbPath(name)
                                os.unlink( fpaf )
                        except:
                                pass # Can't delete it... whatever.

        def thumbPath( self, name ):
                return os.path.join(self.location,'djanthumbs', name)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to