#02 How To Create Collage Using Python Program. 🌱Python Image Library

preview_player
Показать описание
Dear Monkey, Today You Will Learn - How To Create Collage Using Python Program. 🌱Python Image Library.

#coding #python #training #banglacomputertutorial #computer #graphics #turtle #trainingvideo #learning #computermonkeys #imagelibrary
Рекомендации по теме
Комментарии
Автор

import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image, ImageTk

def open_images():
# Ask the user to select three image files
file_paths = files", "*.jpg *.jpeg *.png *.bmp *.gif")], title="Select three images", multiple=True)

if len(file_paths) != 3:
messagebox.showerror("Error", "Please select exactly three images.")
return

# Load and resize images to a common size (e.g., 300x300)
images = []
try:
for path in file_paths:
img = Image.open(path)
img = img.resize((300, 300))
images.append(img)
except Exception as e:
messagebox.showerror("Error", f"Error loading images: {e}")
return

# Calculate the size of the collage
collage_width = sum(img.width for img in images)
collage_height = max(img.height for img in images)

# Create a new blank image for the collage
collage = Image.new('RGB', (collage_width, collage_height))

# Paste each image into the collage at the correct position
x_offset = 0
for img in images:
collage.paste(img, (x_offset, 0))
x_offset += img.width

# Save the collage
collage_path = 'collage.jpg'
collage.save(collage_path)

# Display the collage
collage_tk = ImageTk.PhotoImage(collage)

collage_label.image = collage_tk
collage_label.pack()

# Create the main application window
root = tk.Tk()
root.title("Image Collage Creator")

# Create a button to open image files
open_button = tk.Button(root, text="Open Images", command=open_images)
open_button.pack()

# Create a label to display the collage
collage_label = tk.Label(root)
collage_label.pack()

# Run the application
root.mainloop()

monkeys
welcome to shbcf.ru