mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Moved all pathlib logic out of function
This commit is contained in:
parent
cab7d8a8ab
commit
d455abffee
|
@ -417,13 +417,11 @@ This example uses Pillow together with pathlib, in order to reduce the quality o
|
|||
from PIL import Image
|
||||
|
||||
|
||||
def compress_image(filepath):
|
||||
file = filepath.stem
|
||||
with Image.open(filepath) as img:
|
||||
def compress_image(source_path, dest_path):
|
||||
with Image.open(source_path) as img:
|
||||
if img.mode != "RGB":
|
||||
img = img.convert("RGB")
|
||||
img.save(file + ".jpg", "JPEG", optimize=True, quality=80)
|
||||
return
|
||||
img.save(dest_path, "JPEG", optimize=True, quality=80)
|
||||
|
||||
|
||||
base_directory = Path.cwd()
|
||||
|
@ -431,7 +429,7 @@ This example uses Pillow together with pathlib, in order to reduce the quality o
|
|||
for path in base_directory.iterdir():
|
||||
if path.suffix == ".png":
|
||||
print(path)
|
||||
compress_image(path)
|
||||
compress_image(path, filepath.stem + ".jpg")
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user