Spaces:
No application file

File size: 1,640 Bytes
5600327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
from PIL import Image, ImageDraw, ImageFont
import io

# Function to overlay text on the background image
def create_image_with_name(background_path, name):
    # Load the background image
    bg_image = Image.open(background_path).convert("RGBA")
    draw = ImageDraw.Draw(bg_image)

    # Set font and size
    try:
        font = ImageFont.truetype("arial.ttf", 40)  # Use a font file available on your system
    except:
        font = ImageFont.load_default()

    # Get text size
    text_width, text_height = draw.textsize(name, font=font)

    # Position text in the center
    text_position = ((bg_image.width - text_width) // 2, (bg_image.height - text_height) // 2)

    # Add text to image
    draw.text(text_position, name, font=font, fill=(255, 255, 255, 255))  # White color text

    return bg_image

# Streamlit app layout
st.title("Rose Background with Your Name")
st.write("Enter your name to generate a rose background with your name on it.")

# Input field for name
user_name = st.text_input("Enter your name:")

# Button to generate image
if st.button("Generate"):
    if user_name:
        # Create image with name
        img = create_image_with_name("rose_background.jpg", user_name)

        # Save to a buffer
        buffer = io.BytesIO()
        img.save(buffer, format="PNG")
        buffer.seek(0)

        # Display the image
        st.image(img, caption=f"Rose Background for {user_name}")

        # Provide download link
        st.download_button("Download Image", buffer, file_name=f"{user_name}_rose.png", mime="image/png")
    else:
        st.warning("Please enter a name.")