<<add to top of file>>
import os, Image
TINY_SIZE = (80,80) #thumb size (x,y)
<<add to Model>>
def thumb(self):
tinythumb = self.image.replace('\\','/').split('/')
tinythumb[-1] = 'tiny/'+tinythumb[-1]
tinythumb = '/'.join(tinythumb)
if not os.path.exists(MEDIA_ROOT+tinythumb):
im = Image.open(MEDIA_ROOT+self.image)
im.thumbnail(TINY_SIZE,Image.ANTIALIAS)
im.save(MEDIA_ROOT+tinythumb,"JPEG")
return """<a href="/media/%s"><img src="/media/%s" alt="tiny thumbnail image" /></a>"""%(self.image,tinythumb)
thumb.allow_tags = True
Comments
Hi all, i did try this code but it doesn't work. This code: im = Image.open(MEDIA_ROOT+self.image) im.thumbnail(TINY_SIZE,Image.ANTIALIAS) im.save(MEDIA_ROOT+tinythumb,"JPEG")
don't generate the thumb in the folder "tiny"... I work with Django on OSX.
Can anyone please help me on this? thanks in advance guys.
#
Marco -
Have you installed and imported PIL (Python Imaging Library called: Image)?
If your not sure, from a python prompt try: import Image
What does your traceback look like?
Thomas
#
Hello,
The same idea in a more correct way:
Of course, you should add "from os import path" at the beginning of the file.
Thanks, Dmitriy
#
And more correct for change list:
models.py
admin.py
#