Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

generate-thumbnails-in-django-with-pil

from django.db import models
from my.images import make_thumbnail


class Image(models.Model):
    image = models.ImageField(upload_to='')
    thumbnail = models.ImageField(upload_to='', editable=False)
    icon = models.ImageField(upload_to='', editable=False)

    def save(self, *args, **kwargs):
        # save for image
        super(Image, self).save(*args, **kwargs)

        make_thumbnail(self.thumbnail, self.image, (200, 200), 'thumb')
        make_thumbnail(self.icon, self.image, (100, 100), 'icon')

        # save for thumbnail and icon
        super(Image, self).save(*args, **kwargs)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
6+4 =