Search code examples
djangothumbnailseasy-thumbnails

Remove all thumbnails generated with easy-thumbnails Django App


I am using easy-thumbnails in my Django 1.5 project to generate thumbnail images.

I have been using several different sizes for thumbnails for testing, but now I would like to clear all thumbnails from my filesystem and from the easy-thumbnails database entries. Over time I created several different sizes of many images and I would like to remove those now.

My intention is to start with a clean slate and to remove all thumbnail images. I could not find out how to do that.


Solution

  • Just had the same problem.

    Given:

    class MyModel(Model):
        image = ThumbnailerImageField()
    

    You can delete all thumbnails with:

    for m in MyModel.objects.all():
        m.image.delete_thumbnails()
    

    If you instead have:

    class MyModel(Model):
        image = ImageField()
    

    Then you should use:

    from easy_thumbnails.files import get_thumbnailer
    
    for m in MyModel.objects.all():
        thumbnailer = get_thumbnailer(m.image)
        thumbnailer.delete_thumbnails()