-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_editor.py
More file actions
26 lines (20 loc) · 900 Bytes
/
Copy pathimage_editor.py
File metadata and controls
26 lines (20 loc) · 900 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
from PIL import Image, ImageEnhance, ImageFilter
import os
img = r"C:\Users\LENOVO\OneDrive\Pictures"
files = os.listdir(img)
for file in files:
if file.endswith((".jpg", ".jpeg", ".png")):
file_path = os.path.join(img, file)
try:
with Image.open(file_path) as image:
# Enhance the image
enhancer = ImageEnhance.Contrast(image)
enhanced_image = enhancer.enhance(1.5) # Increase contrast by 50%
# Apply a filter
filtered_image = enhanced_image.filter(ImageFilter.SHARPEN)
# Save the edited image
# Overwrite the original file
filtered_image.save(file_path)
print(f"✅ Edited {file}")
except Exception as e:
print(f"❌ Error processing {file}: {e}")