resize the image. But when i do this images that are in the same
directory seem to get resized aswell even though they have unique hash
names? any help please.
MODELS.py
def upload_to(instance, old_filename):
import time
import hashlib
import os
extension = os.path.splitext(old_filename)[1]
filename = hashlib.md5(str(time.time())).hexdigest() + extension
return "photos/%s/%s" % (instance.userprofile.user_id, filename)
class UserProfilePic(models.Model):
current = models.BooleanField()
userprofile = models.ForeignKey(UserProfile)
profilepic = models.ImageField(upload_to=upload_to)
def save(self):
from PIL import Image, ImageOps
super(UserProfilePic, self).save()
#create profile image
filename2 = self.profilepic.path
im2 = Image.open(filename2)
im2 = ImageOps.fit(im2, (170, 190), Image.ANTIALIAS,
(0.5,0.5)).save(filename, "JPEG", quality=100)
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment