-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeimages.py
31 lines (24 loc) · 1.02 KB
/
mergeimages.py
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
from PIL import Image
import os
def merge_images(image1_path, image2_path, output_path):
print(f"Merging: {os.path.basename(image1_path)} + {os.path.basename(image2_path)}")
# Open both images
base = Image.open(image1_path)
overlay = Image.open(image2_path)
# Convert both to RGBA if they aren't already
if base.mode != 'RGBA':
base = base.convert('RGBA')
if overlay.mode != 'RGBA':
overlay = overlay.convert('RGBA')
# Create new merged image
merged = Image.alpha_composite(base, overlay)
# Save merged image
merged.save(output_path, 'PNG')
print(f"Created: {os.path.basename(output_path)}")
if __name__ == "__main__":
image1 = "C:/Users/KFX/OneDrive/Documents/emojis/png/people/image1.png"
image2 = "C:/Users/KFX/OneDrive/Documents/emojis/png/people/image2.png"
result = "C:/Users/KFX/OneDrive/Documents/emojis/png/people/merged.png"
print("Starting image merge...")
merge_images(image1, image2, result)
print("Merge completed!")