From 52ac725ae0110cfcd74a2d090a85cdbda22e21b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Hendrik=20M=C3=BCller?= <44469195+kolibril13@users.noreply.github.com> Date: Wed, 1 Dec 2021 23:06:52 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/handbook/tutorial.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/handbook/tutorial.rst b/docs/handbook/tutorial.rst index abb1605ac..b5d7407da 100644 --- a/docs/handbook/tutorial.rst +++ b/docs/handbook/tutorial.rst @@ -409,7 +409,7 @@ Using the ImageSequence Iterator class Batch processing with Pathlib ----------------------------- -This example uses PIL togehter with pathlib, in order to reduce the quality of all png images in a folder +This example uses PIL together with pathlib, in order to reduce the quality of all png images in a folder :: @@ -419,13 +419,13 @@ This example uses PIL togehter with pathlib, in order to reduce the quality of a def compressImg(filepath, verbose=False): file = filepath.stem - img = Image.open(filepath) - if img.mode != 'RGB': - img = img.convert('RGB') - img.save(file + ".jpg", - "JPEG", - optimize=True, - quality=80) + with Image.open(filepath) as img: + if img.mode != 'RGB': + img = img.convert('RGB') + img.save(file + ".jpg", + "JPEG", + optimize=True, + quality=80) return