automatic image resize in Django for thumbnails

Want to resize images uploaded to Django on the fly? It's actually very simple. This solution requires the Python Imaging Library (PIL).

import Image

class Company(models.Model):

    logo = models.ImageField(upload_to="static/images/logos")

    def save(self, force_insert=False, force_update=False):
        super(Company, self).save(force_insert, force_update)

        if is not None:
            previous = Company.objects.get(
            if self.logo and self.logo != previous.logo:
                image =
                image = image.resize((96, 96), Image.ANTIALIAS)

Updated: Django 1.2 requires that you save the file FIRST, otherwise the path will not be correct.

I'm currently working at NerdWallet, a startup in San Francisco trying to bring clarity to all of life's financial decisions. We're hiring like crazy. Hit me up on Twitter, I would love to talk.

Follow @chase_seibert on Twitter