imageProcessing / app.py
rizwanaidris2's picture
Create app.py
6ed8b17 verified
raw
history blame
1.47 kB
import streamlit as st
from PIL import Image, ImageEnhance, ImageOps
import io
# Function to apply filters to the image
def apply_filter(image, filter_type):
if filter_type == 'Grayscale':
return ImageOps.grayscale(image)
elif filter_type == 'Brightness':
enhancer = ImageEnhance.Brightness(image)
return enhancer.enhance(1.5) # Adjust brightness factor (1.0 is original)
return image
# Set up the Streamlit app
st.title("Simple Image Editor")
# Image upload
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
# Open the image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Options for filters
filter_type = st.selectbox("Choose a filter", ["None", "Grayscale", "Brightness"])
if filter_type != "None":
# Apply the selected filter
edited_image = apply_filter(image, filter_type)
st.image(edited_image, caption=f"Edited Image with {filter_type} filter", use_column_width=True)
# Convert edited image to bytes for download
img_byte_arr = io.BytesIO()
edited_image.save(img_byte_arr, format="PNG")
img_byte_arr = img_byte_arr.getvalue()
# Allow the user to download the edited image
st.download_button(
label="Download Edited Image",
data=img_byte_arr,
f