File size: 4,339 Bytes
950330c
8662504
950330c
8662504
d61c3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
950330c
d61c3f8
8662504
 
d61c3f8
 
 
 
 
 
 
 
 
8662504
d61c3f8
8662504
d61c3f8
 
 
 
 
 
 
 
 
75dde25
d61c3f8
75dde25
 
 
d61c3f8
75dde25
 
d61c3f8
 
726ab2a
 
 
 
 
 
 
d61c3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75dde25
 
 
d61c3f8
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
from PIL import Image, ImageEnhance, ImageFilter

# Custom CSS Styling
def apply_custom_css():
    st.markdown("""
        <style>
            body {
                background-color: #f4f4f4;
            }
            .main {
                background-color: #ffffff;
                padding: 20px;
                border-radius: 10px;
                box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
            }
            .stButton > button {
                background-color: #007BFF;
                color: white;
                border-radius: 5px;
                padding: 10px 20px;
            }
            .stButton > button:hover {
                background-color: #0056b3;
            }
            .stSidebar {
                background-color: #f8f9fa;
            }
        </style>
    """, unsafe_allow_html=True)

# Function to apply image filters
def apply_filters(image, grayscale, sepia, brightness, contrast, blur, flip, crop):
    if grayscale:
        image = image.convert("L")
    if sepia:
        sepia_filter = ImageEnhance.Color(image)
        image = sepia_filter.enhance(1.5)
    if brightness != 1.0:
        enhancer = ImageEnhance.Brightness(image)
        image = enhancer.enhance(brightness)
    if contrast != 1.0:
        enhancer = ImageEnhance.Contrast(image)
        image = enhancer.enhance(contrast)
    if blur > 0:
        image = image.filter(ImageFilter.GaussianBlur(blur))
    if flip == "Horizontal":
        image = image.transpose(Image.FLIP_LEFT_RIGHT)
    elif flip == "Vertical":
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
    if crop:
        left, top, right, bottom = crop
        image = image.crop((left, top, right, bottom))
    return image

# Main Application
def main():
    apply_custom_css()

    # Title and Banner
    st.title("✨ Advanced Image Editor Pro")
    st.markdown(
        "Edit, Enhance, and Download Your Images Instantly with Professional Filters"
    )

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

    if uploaded_image:
        # Load the uploaded image
        try:
            image = Image.open(uploaded_image)
            st.image(image, caption="Original Image", use_container_width=True)
        except Exception as e:
            st.error(f"Error loading image: {e}")
            return

        # Sidebar Filters
        st.sidebar.header("🎨 Customize Your Image")

        # Filter Options
        grayscale = st.sidebar.checkbox("Apply Grayscale")
        sepia = st.sidebar.checkbox("Apply Sepia")
        brightness = st.sidebar.slider("Brightness πŸ”†", 0.5, 3.0, 1.0)
        contrast = st.sidebar.slider("Contrast 🌟", 0.5, 3.0, 1.0)
        blur = st.sidebar.slider("Blur Level 🌫️", 0, 10, 0)
        flip = st.sidebar.radio("Flip Image πŸ”„", ["None", "Horizontal", "Vertical"])

        # Crop Image
        st.sidebar.header("Crop Image βœ‚οΈ")
        left = st.sidebar.slider("Left", 0, image.width, 0)
        top = st.sidebar.slider("Top", 0, image.height, 0)
        right = st.sidebar.slider("Right", left + 10, image.width, image.width)
        bottom = st.sidebar.slider("Bottom", top + 10, image.height, image.height)
        crop = (left, top, right, bottom) if left < right and top < bottom else None

        # Apply Filters
        edited_image = apply_filters(image, grayscale, sepia, brightness, contrast, blur, flip, crop)

        # Display Edited Image
        st.subheader("Edited Image")
        st.image(edited_image, caption="Your Enhanced Image", use_container_width=True)

        # Download Section
        st.sidebar.header("πŸ“₯ Download Your Image")
        edited_image_path = "edited_image.png"
        edited_image.save(edited_image_path)
        with open(edited_image_path, "rb") as file:
            st.sidebar.download_button(
                label="Download Enhanced Image πŸ“‚",
                data=file,
                file_name="edited_image.png",
                mime="image/png"
            )
    else:
        # Message when no image is uploaded
        st.info("πŸ‘† Upload an image to start editing.")

    # Footer
    st.markdown("---")
    st.markdown("Designed with ❀️ using Streamlit. Happy Editing!")

# Run the app
if __name__ == "__main__":
    main()