-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotoeditor.py
More file actions
32 lines (23 loc) · 1015 Bytes
/
Copy pathphotoeditor.py
File metadata and controls
32 lines (23 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image, ImageFilter
import os
path = "Write the address of the location where the images are located"
pathOut = "Type the address of the file where the edited images will be placed"
if not os.path.exists(pathOut):
os.makedirs(pathOut)
for filename in os.listdir(path):
img_path = os.path.join(path, filename)
if os.path.isfile(img_path):
try:
img = Image.open(img_path)
edit = img.filter(ImageFilter.SHARPEN).convert("L")
factor=1.5
enhancer=ImageEnhance.Contrast(edit)
edit=enhancer.enhance(factor)
clean_name = os.path.splitext(filename)[0]
save_path = os.path.join(pathOut, f"{clean_name}_edited.jpg")
edit.save(save_path)
print(f"{filename} processed and saved as {save_path}.")
except Exception as e:
print(f"{filename} An error occurred while processing: {e}")
else:
print(f"{img_path} is not a file or does not exist.")