How to optimize images in Python

This can be done in many ways. We will do through the module pyllow

Installation

Install inside the virtual environment:

Using

from PIL import Image
from datetime import datetime

timestamp = datetime.now().timestamp()

path = ‘public / build / screenshots’
img = f‘{path} /screenshot.png’

im = Image.open(img)
im = im.convert(“RGB”)
im = im.resize((1200, 750), Image.ANTIALIAS)
im.save(f“{path} / {timestamp} .jpg”, optimize= True, quality=75)

Can be combined with Python screenshots.

Similar Posts

Leave a Reply