9951 explained code solutions for 126 technologies


python-pillowHow to compress an image


Compression level can be increased by lowering quality value:

from PIL import Image, ImageDraw, ImageFont

im = Image.open('/var/www/examples/heroine.png')
im.save('out.jpg', quality=75)ctrl + c
PIL

import Pillow package modules

Image.open

open given image with Pillow

.save(

saves image under given path (format is automatically picked based on file extension)

quality

sets JPG quality value (lower quality values reduce file size)

75

out of 100, use lower values to reduce file size even more