Hi All,

        Can Any one help me to resize all types of (like jpeg,gif ect....)
images.
        This code only useful to upload Jpeg images only. When I upload a
image 'thumbnail' folder has two images   and when I delete the image only
one image is deleted from folder(Resized image or thumbnail image ).I need
        to delete both the images .
        Please advise me.
        thanks.

models.py
`````````

from __future__ import division
import os
import tempfile
import Image
from django.core.files import File



class Picture(models.Model):
    name = models.CharField(max_length=200)
    thumbnail = models.ImageField(upload_to='thumbnail')

    def save(self, force_update=False, force_insert=False):
           orig = Image.open(self.thumbnail.path)
           name = os.path.basename(self.thumbnail.name)
           width = 100
           height = 100
           thumb = orig.resize((width, height), Image.ANTIALIAS)
           thumb_file = tempfile.NamedTemporaryFile('w+b')
           thumb.save(thumb_file,'JPEG')
           self.thumbnail.save(name, File(thumb_file), False)
           thumb_file.close() #tempfile is deleted upon close:)
           super(Picture, self).save(force_update, force_insert)

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to