mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Apply suggestions from code review
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
parent
21351c8982
commit
cab7d8a8ab
|
@ -406,26 +406,23 @@ Using the ImageSequence Iterator class
|
||||||
# ...do something to frame...
|
# ...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 pathlib import Path
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def compressImg(filepath):
|
def compress_image(filepath):
|
||||||
file = filepath.stem
|
file = filepath.stem
|
||||||
with Image.open(filepath) as img:
|
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", optimize=True, quality=80)
|
||||||
"JPEG",
|
|
||||||
optimize=True,
|
|
||||||
quality=80)
|
|
||||||
return
|
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():
|
for path in base_directory.iterdir():
|
||||||
if path.suffix == ".png":
|
if path.suffix == ".png":
|
||||||
print(path)
|
print(path)
|
||||||
compressImg(path)
|
compress_image(path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user