Here is a basic example of how you can create a GUI in Python to download an image and add a title to it using the H1 font:
import tkinter as tk
from tkinter import filedialog
import urllib.request
from PIL import Image, ImageFont, ImageDraw
# Create the main window
window = tk.Tk()
window.title(“Image Title Generator”)
# Function to download the image and add the title
def generate_image():
# Get the URL and title from the user input
url = url_entry.get()
title = title_entry.get()
# Download the image from the URL
response = urllib.request.urlopen(url)
data = response.read()
# Open the image and create an ImageDraw object
image = Image.open(io.BytesIO(data))
draw = ImageDraw.Draw(image)
# Select the H1 font and get the size of the title
font = ImageFont.truetype(“Helvetica.ttf”, 36)
title_width, title_height = draw.textsize(title, font=font)
# Calculate the position of the title
x = (image.width – title_width) // 2
y = 10
# Draw the title on the image
draw.text((x, y), title, font=font, fill=(255, 255, 255))
# Save the image to a file
image.save(“titled_image.jpg”)
# Create the input fields and button
url_label = tk.Label(window, text=”Image URL:”)
url_entry = tk.Entry(window)
title_label = tk.Label(window, text=”Title:”)
title_entry = tk.Entry(window)
button = tk.Button(window, text=”Generate Image”, command=generate_image)
# Place the input fields and button in the window
url_label.pack()
url_entry.pack()
title_label.pack()
title_entry.pack()
button.pack()
# Run the main loop
window.mainloop()
his code creates a window with two input fields for the URL and the title, and a button to generate the image. When the button is clicked, the generate_image
function is called, which downloads the image from the URL, adds the title using the H1 font, and saves the image to a file called “titled_image.jpg”.
You may need to install additional libraries such as Pillow
and fonts-liberation
to use this code. You can also customize the appearance and layout of the GUI to suit your needs.