Moldytzu
Moldytzu

Reputation: 25

Is there any way to make PIL's ImageGrab.grab() save photos with a small size?

I'm using PIL with Python 3.8 to make screenshots of my screeen but the size of them is too large. How can I reduce it?

Upvotes: 0

Views: 1411

Answers (2)

user12797553
user12797553

Reputation:

from PIL import Image
im = Image.open("hopper.jpg")
# Provide the target width and height of the image
(width, height) = (im.width // 2, im.height // 2)
im_resized = im.resize((width, height))

source PIL Docs

Upvotes: 1

Kexus
Kexus

Reputation: 659

You can use Image.resize() to shrink the image prior to saving.

Upvotes: 1

Related Questions