File size: 2,370 Bytes
95a28bd 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 353dd66 03af3d1 816e982 03af3d1 353dd66 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 95a28bd 03af3d1 816e982 | 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 | import streamlit as st
from PIL import Image, ImageEnhance, ImageOps
from io import BytesIO
# App title and description
st.set_page_config(page_title="Image Editor", page_icon="π¨", layout="wide")
st.title("π¨ Image Editor")
st.write("Easily upload, enhance, and download your images with a variety of filters and adjustments.")
# Sidebar for navigation
st.sidebar.header("ποΈ Image Editing Options")
# File upload
uploaded_file = st.sidebar.file_uploader("π€ Upload an Image", type=["png", "jpg", "jpeg"])
if uploaded_file:
# Display original image
col1, col2 = st.columns(2)
with col1:
st.header("Original Image")
image = Image.open(uploaded_file)
st.image(image, use_container_width=True)
# Editing options
with col2:
st.header("Edited Image")
edited_image = image.copy()
# Grayscale
if st.sidebar.checkbox("π³ Convert to Grayscale"):
edited_image = ImageOps.grayscale(edited_image)
# Brightness
brightness = st.sidebar.slider("π‘ Brightness", 0.5, 2.0, 1.0)
enhancer = ImageEnhance.Brightness(edited_image)
edited_image = enhancer.enhance(brightness)
# Contrast
contrast = st.sidebar.slider("ποΈ Contrast", 0.5, 2.0, 1.0)
enhancer = ImageEnhance.Contrast(edited_image)
edited_image = enhancer.enhance(contrast)
# Sharpness
sharpness = st.sidebar.slider("πͺ Sharpness", 0.5, 3.0, 1.0)
enhancer = ImageEnhance.Sharpness(edited_image)
edited_image = enhancer.enhance(sharpness)
# Add border
if st.sidebar.checkbox("πΌοΈ Add Border"):
border_size = st.sidebar.slider("Border Size", 1, 50, 10)
border_color = st.sidebar.color_picker("Border Color", "#000000")
edited_image = ImageOps.expand(edited_image, border=border_size, fill=border_color)
# Display edited image
st.image(edited_image, use_container_width=True)
# Download button
buf = BytesIO()
edited_image.save(buf, format="PNG")
byte_im = buf.getvalue()
st.download_button(
label="π₯ Download Edited Image",
data=byte_im,
file_name="edited_image.png",
mime="image/png",
)
else:
st.info("π Upload an image to get started!") |