开发者

django - save a resize copy of image on upload (using admin site)

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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜