mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-29 17:33:08 +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
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def compress_image(filepath):
|
def compress_image(source_path, dest_path):
|
||||||
file = filepath.stem
|
with Image.open(source_path) 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", "JPEG", optimize=True, quality=80)
|
img.save(dest_path, "JPEG", optimize=True, quality=80)
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
base_directory = Path.cwd()
|
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():
|
for path in base_directory.iterdir():
|
||||||
if path.suffix == ".png":
|
if path.suffix == ".png":
|
||||||
print(path)
|
print(path)
|
||||||
compress_image(path)
|
compress_image(path, filepath.stem + ".jpg")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user