Spaces:
Sleeping
Sleeping
File size: 3,494 Bytes
797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 797c6e1 b4d0d89 |
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 |
import streamlit as st
from PIL import Image, ImageEnhance, ImageFilter
import io
# Function to apply grayscale filter
def apply_grayscale(img):
return img.convert("L")
# Function to adjust brightness
def adjust_brightness(img, factor):
enhancer = ImageEnhance.Brightness(img)
return enhancer.enhance(factor)
# Function to adjust contrast
def adjust_contrast(img, factor):
enhancer = ImageEnhance.Contrast(img)
return enhancer.enhance(factor)
# Function to adjust sharpness
def adjust_sharpness(img, factor):
enhancer = ImageEnhance.Sharpness(img)
return enhancer.enhance(factor)
# Function to rotate image
def rotate_image(img, angle):
return img.rotate(angle)
# Function to resize image
def resize_image(img, width, height):
return img.resize((width, height))
# Function to apply a blur filter
def apply_blur(img):
return img.filter(ImageFilter.BLUR)
# Streamlit Interface
def main():
st.title("Advanced Image Editor")
# Upload image
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Open the image
img = Image.open(uploaded_file)
# Display the uploaded image
st.image(img, caption="Uploaded Image", use_column_width=True)
# Apply Grayscale Filter
if st.checkbox("Apply Grayscale"):
img = apply_grayscale(img)
st.image(img, caption="Grayscale Image", use_column_width=True)
# Brightness Adjustment
brightness_factor = st.slider("Adjust Brightness", 0.5, 2.0, 1.0)
img = adjust_brightness(img, brightness_factor)
st.image(img, caption=f"Brightness Adjusted (Factor: {brightness_factor})", use_column_width=True)
# Contrast Adjustment
contrast_factor = st.slider("Adjust Contrast", 0.5, 2.0, 1.0)
img = adjust_contrast(img, contrast_factor)
st.image(img, caption=f"Contrast Adjusted (Factor: {contrast_factor})", use_column_width=True)
# Sharpness Adjustment
sharpness_factor = st.slider("Adjust Sharpness", 0.5, 2.0, 1.0)
img = adjust_sharpness(img, sharpness_factor)
st.image(img, caption=f"Sharpness Adjusted (Factor: {sharpness_factor})", use_column_width=True)
# Rotate Image
rotation_angle = st.slider("Rotate Image", 0, 360, 0)
if rotation_angle != 0:
img = rotate_image(img, rotation_angle)
st.image(img, caption=f"Rotated Image (Angle: {rotation_angle}°)", use_column_width=True)
# Resize Image
new_width = st.slider("Resize Image - Width", 100, 2000, img.width)
new_height = st.slider("Resize Image - Height", 100, 2000, img.height)
if new_width != img.width or new_height != img.height:
img = resize_image(img, new_width, new_height)
st.image(img, caption=f"Resized Image ({new_width}x{new_height})", use_column_width=True)
# Apply Blur Filter
if st.checkbox("Apply Blur"):
img = apply_blur(img)
st.image(img, caption="Blurred Image", use_column_width=True)
# Download Button
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img_byte_arr.seek(0)
st.download_button(
label="Download Edited Image",
data=img_byte_arr,
file_name="edited_image.png",
mime="image/png"
)
# Run the app
if __name__ == "__main__":
main()
|