Search code examples
pythondjangosummernote

how to compress the size of the picture in django-summernote


The task of tako with how can you compress the image uploaded through django-summernote For example, I have a picture with a size of 5mb after downloading it should have a size somewhere 500kb


Solution

  • Edit the paths as you wish and choose one of the two when finished:

    from PIL import Image
    foo = Image.open("path to image")
    foo = foo.resize((720, 405), Image.ANTIALIAS)
    foo.save("path to first new image", quality=95)
    foo.save("path to second new image", optimize=True, quality=95)