From cab7d8a8ab77f3dce3a536902ea7307e7e115b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Hendrik=20M=C3=BCller?= <44469195+kolibril13@users.noreply.github.com> Date: Thu, 2 Dec 2021 16:20:13 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Hugo van Kemenade --- docs/handbook/tutorial.rst | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/handbook/tutorial.rst b/docs/handbook/tutorial.rst index 26625eacc..e4848fa62 100644 --- a/docs/handbook/tutorial.rst +++ b/docs/handbook/tutorial.rst @@ -406,26 +406,23 @@ Using the ImageSequence Iterator class # ...do something to frame... -Batch processing with Pathlib +Batch processing with pathlib ----------------------------- -This example uses PIL together with pathlib, in order to reduce the quality of all png images in a folder +This example uses Pillow together with pathlib, in order to reduce the quality of all PNG images in a folder: :: - from PIL import Image from pathlib import Path + from PIL import Image - def compressImg(filepath): + def compress_image(filepath): file = filepath.stem with Image.open(filepath) as img: - if img.mode != 'RGB': - img = img.convert('RGB') - img.save(file + ".jpg", - "JPEG", - optimize=True, - quality=80) + if img.mode != "RGB": + img = img.convert("RGB") + img.save(file + ".jpg", "JPEG", optimize=True, quality=80) return @@ -434,7 +431,7 @@ This example uses PIL together with pathlib, in order to reduce the quality of a for path in base_directory.iterdir(): if path.suffix == ".png": print(path) - compressImg(path) + compress_image(path)