mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-24 19:22:00 +03:00
Apply suggestions from code review
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
This commit is contained in:
parent
af924a1f96
commit
52ac725ae0
|
@ -409,7 +409,7 @@ Using the ImageSequence Iterator class
|
||||||
Batch processing with Pathlib
|
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):
|
def compressImg(filepath, verbose=False):
|
||||||
file = filepath.stem
|
file = filepath.stem
|
||||||
img = Image.open(filepath)
|
with Image.open(filepath) as img:
|
||||||
if img.mode != 'RGB':
|
if img.mode != 'RGB':
|
||||||
img = img.convert('RGB')
|
img = img.convert('RGB')
|
||||||
img.save(file + ".jpg",
|
img.save(file + ".jpg",
|
||||||
"JPEG",
|
"JPEG",
|
||||||
optimize=True,
|
optimize=True,
|
||||||
quality=80)
|
quality=80)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user