File size: 2,500 Bytes
87b80b6
 
 
e599666
 
7b6ed39
e599666
 
 
7b6ed39
e599666
 
 
 
 
 
 
 
 
 
aafa388
 
e599666
 
 
 
 
 
 
 
 
 
87b80b6
 
 
 
e599666
87b80b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bad1ff6
1583968
bad1ff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st
from PIL import Image, ImageEnhance
import io
import requests

# Background Image URL (Corrected for direct download)
background_url = "https://drive.google.com/uc?id=1I9IbcLTS2FIsWfAa1A5XA-2NdrMIuy-t"

def set_background_from_url(url):
    """Set the background image of the app using a URL."""
    response = requests.get(url)
    if response.status_code == 200:
        with open("background.jpg", "wb") as f:
            f.write(response.content)
        st.markdown(
            """
            <style>
            .stApp {
                background-image: url('background.jpg');
                background-size: cover;
                background-repeat: no-repeat;
                background-attachment: fixed;
            }
            </style>
            """,
            unsafe_allow_html=True
        )
    else:
        st.error("Unable to load the background image.")

# Set background image
set_background_from_url(background_url)

st.title("Image Editor")

# Upload an image
uploaded_image = st.file_uploader("Add Image", type=["jpg", "jpeg", "png"])

if uploaded_image:
    image = Image.open(uploaded_image)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Sidebar for filters
    st.sidebar.header("Adjust Filters")
    brightness = st.sidebar.slider("Brightness", 0.1, 3.0, 1.0)
    contrast = st.sidebar.slider("Contrast", 0.1, 3.0, 1.0)
    sharpness = st.sidebar.slider("Sharpness", 0.1, 3.0, 1.0)

    # Resize options
    st.sidebar.header("Resize Image")
    width = st.sidebar.number_input("Width", value=image.width, step=1)
    height = st.sidebar.number_input("Height", value=image.height, step=1)

    # Apply Brightness
    enhancer_brightness = ImageEnhance.Brightness(image)
    image = enhancer_brightness.enhance(brightness)

    # Apply Contrast
    enhancer_contrast = ImageEnhance.Contrast(image)
    image = enhancer_contrast.enhance(contrast)

    # Apply Sharpness
    enhancer_sharpness = ImageEnhance.Sharpness(image)
    image = enhancer_sharpness.enhance(sharpness)

    # Resize image
    image = image.resize((int(width), int(height)))

    # Display edited image
    st.image(image, caption="Edited Image", use_column_width=True)

    # Convert to bytes for download
    img_bytes = io.BytesIO()
    image.save(img_bytes, format="PNG")
    img_bytes = img_bytes.getvalue()

    # Download button
    st.download_button("Download Image", data=img_bytes, file_name="edited_image.png", mime="image/png")