Enrico wrote:
> Hi,
> 
> I'm trying to resize an image automatically after the upload. Maybe
> Django should have this by default, but until there I'll try myself...
> 
> I got it working sucessfully, but I don't know if this is the best way,
> the image is processed every time I save the object, it should be done
> only on new uploads.
> 
> My model:
> 
> class pic(models.Model):
>       name = models.CharField(maxlength=60, core=True)
>       pic = models.ImageField(upload_to='news')
> 
>       def save(self):
>               file_path = self.get_pic_filename()
>               # There's is a file?
>               if (file_path):
>                       im = Image.open(file_path)
>                       # Using my own image resizing based on PIL
>                       im = image_util.best_fit(im, 30, 30)
>                       im.save(file_path)
>               super(news_pic, self).save()
> 
>       class Admin:
>               pass
> 
> Is there a better way to do it?
> 
> How hard would be to create a "custom" ImageField for this?
> It could be used in many other models in my project, and could even get
> included in the Django package.


Try http://trac.studioquattro.biz/djangoutils/wiki/Thumbnail (shameless self 
promotion ;) )


-- 
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
http://djnesh.blogspot.com/  |  http://djnesh-django.blogspot.com/ |  
http://trac.studioquattro.biz/djangoutils/
Registered Linux User 282159 [http://counter.li.org]

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to