In Python's PIL, how do I change the quality of an image?
I want to degrade the quality of the image to a few kilobytes. What's the best way to do this?
If the picture format is JPEG, here's an example:
from PIL import Image im = Image.open("C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg") im.save("C:\Users\Public\Pictures\Sample Pictures\Jellyfish_compressed.jpg", quality=10)
The references you need to be reading are:
- [The Image module], particularly the "save" function, which allows you to pass in options relevant for each image format.
- Each image format's options are in a different page, you can find it in the docs.