0 votes
in Python Imaging Library by
How can you use PIL to compress an image without losing its quality?

1 Answer

0 votes
by
PIL can be used to compress an image without losing quality by using the “save” function with the “quality” parameter set to a high value. First, import PIL and open the image file. Then, use the “resize” method to reduce the size of the image while maintaining its aspect ratio. Finally, save the compressed image using the “save” function with the “quality” parameter set to 95 or higher. This will ensure that the image is compressed without significant loss in quality. Here’s a code example:

from PIL import Image

img = Image.open('image.jpg')

resized_img = img.resize((500, 500))

resized_img.save('compressed_image.jpg', 'JPEG', quality=95)

Related questions

0 votes
asked Oct 1, 2023 in Python Imaging Library by sharadyadav1986
0 votes
asked Oct 2, 2023 in Python Imaging Library by sharadyadav1986
...