views:

433

answers:

2

Hi -

I'm building a site for a client that needs to support image uploads (an artist) through the admin interface. Since most of the images are pretty high-res, I wanted to create thumb copies of the image to display on the gallery page after the upload. The upload works great with the forms.ImageFile element, but I was looking for some ideas on how to do the actual resizing and and linking between the thumb and the true size images. I had an idea to hold model class for both an image and an image thumb:

from django.db import models

class Image(models.Model):
    """a true size image"""
    image = models.ImageFile(upload_to="images")
    desc = models.CharField(max_length=256)

    class Meta:
        db_table = "images"

class ImageThumb(models.Model):
    """"a thumbnail of an actual image"""
    real_image = models.ForeignKey('Image')
    image = models.ImageField(upload_to="images/thumbs")

    class Meta:
        db_table = "thumbs"

That part I'm stuck on is how to resize the real image after upload (pil? how?), and I could probably use some polishing on my models - any help will be great. Thanks.

+3  A: 

There's a great plugin called sorl-thumbnail that deals with thumbnail generation - don't bother doing it yourself. sorl-thumbnail is very configurable, so the chances are it'll do anything you want it to do.

If that doesn't work for you, then photologue is also very good (photologue is more tailored towards managing photo albums, rather than just plain thumbnail generation).

Dominic Rodger
+1 for sorl-thumbnail. It is very easy to set up and use.
Andre Miller
A: 

See also easy-thumbnails and aino-convert. They might be a good bet since sorl-thumbnail might not be developed very actively from now on.

akaihola