from PIL import Image b = Book.objects.get(title='Into the wild') image = Image.open(b.cover_pic.path) image.save(b.image.path,quality=20,optimize=True)
Here is what the above code is Doing:
1. We are getting the book object from the database.
2. We are opening the image file using the Image.open() method.
3. We are saving the image file using the image.save() method.
4. We are passing the path of the image file as the first argument.
5. We are passing the quality of the image as the second argument.
6. We are passing the optimize flag as the third argument.
The quality of the image is set to 20.
The optimize flag is set to True.