Apply suggestions from code review

Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
This commit is contained in:
Jan-Hendrik Müller 2021-12-01 23:06:52 +01:00 committed by GitHub
parent af924a1f96
commit 52ac725ae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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