meetfahad1 commited on
Commit
a2daaf1
·
verified ·
1 Parent(s): a04a4a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -2,45 +2,50 @@ import streamlit as st
2
  from PIL import Image, ImageEnhance
3
 
4
  def main():
5
- st.title("Image Editor")
6
 
7
  st.sidebar.header("Features")
8
  uploaded_file = st.sidebar.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
9
 
10
  if uploaded_file:
 
11
  image = Image.open(uploaded_file)
 
 
 
12
  st.image(image, caption="Uploaded Image", use_column_width=True)
13
 
14
- # Apply filters
15
  st.sidebar.subheader("Adjustments")
16
-
17
  # Grayscale
18
  grayscale = st.sidebar.checkbox("Apply Grayscale")
19
-
20
- # Brightness
21
  brightness = st.sidebar.slider("Adjust Brightness", 0.5, 2.0, 1.0, 0.1)
22
-
23
- # Contrast
24
- contrast = st.sidebar.slider("Adjust Contrast", 0.5, 2.0, 1.0, 0.1)
25
-
26
- # Sharpness
27
- sharpness = st.sidebar.slider("Adjust Sharpness", 0.5, 2.0, 1.0, 0.1)
28
-
29
- # Rotation
30
  rotate_angle = st.sidebar.slider("Rotate Image (Degrees)", 0, 360, 0, 15)
31
-
32
- # Flip
33
- flip_horizontal = st.sidebar.checkbox("Flip Horizontally")
34
- flip_vertical = st.sidebar.checkbox("Flip Vertically")
35
 
36
- # Crop
37
- crop_left = st.sidebar.number_input("Crop Left (px)", 0, image.width, 0)
38
- crop_top = st.sidebar.number_input("Crop Top (px)", 0, image.height, 0)
39
- crop_right = st.sidebar.number_input("Crop Right (px)", 0, image.width, image.width)
40
- crop_bottom = st.sidebar.number_input("Crop Bottom (px)", 0, image.height, image.height)
 
 
 
 
41
 
42
- edited_image = image
 
 
 
43
 
 
44
  if grayscale:
45
  edited_image = edited_image.convert("L")
46
 
@@ -49,32 +54,28 @@ def main():
49
  edited_image = edited_image.convert("RGB")
50
  enhancer = ImageEnhance.Brightness(edited_image)
51
  edited_image = enhancer.enhance(brightness)
52
-
53
- if contrast != 1.0:
54
- if edited_image.mode != "RGB":
55
- edited_image = edited_image.convert("RGB")
56
- enhancer = ImageEnhance.Contrast(edited_image)
57
- edited_image = enhancer.enhance(contrast)
58
-
59
- if sharpness != 1.0:
60
  if edited_image.mode != "RGB":
61
  edited_image = edited_image.convert("RGB")
62
- enhancer = ImageEnhance.Sharpness(edited_image)
63
- edited_image = enhancer.enhance(sharpness)
64
-
65
  if rotate_angle != 0:
66
  edited_image = edited_image.rotate(rotate_angle)
67
 
 
 
 
68
  if flip_horizontal:
69
  edited_image = edited_image.transpose(Image.FLIP_LEFT_RIGHT)
70
 
71
  if flip_vertical:
72
  edited_image = edited_image.transpose(Image.FLIP_TOP_BOTTOM)
73
 
74
- if crop_left < crop_right and crop_top < crop_bottom:
75
- edited_image = edited_image.crop((crop_left, crop_top, crop_right, crop_bottom))
76
-
77
- st.image(edited_image, caption="Edited Image", use_column_width=True)
78
 
79
  # Download button
80
  st.sidebar.subheader("Download")
 
2
  from PIL import Image, ImageEnhance
3
 
4
  def main():
5
+ st.title("Interactive Image Editor")
6
 
7
  st.sidebar.header("Features")
8
  uploaded_file = st.sidebar.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
9
 
10
  if uploaded_file:
11
+ # Load the image
12
  image = Image.open(uploaded_file)
13
+ edited_image = image.copy()
14
+
15
+ st.subheader("Original Image")
16
  st.image(image, caption="Uploaded Image", use_column_width=True)
17
 
18
+ # Adjustment Tools
19
  st.sidebar.subheader("Adjustments")
20
+
21
  # Grayscale
22
  grayscale = st.sidebar.checkbox("Apply Grayscale")
23
+
24
+ # Brightness Adjustment
25
  brightness = st.sidebar.slider("Adjust Brightness", 0.5, 2.0, 1.0, 0.1)
26
+
27
+ # Color Enhancement
28
+ color = st.sidebar.slider("Adjust Color Intensity", 0.5, 2.0, 1.0, 0.1)
29
+
30
+ # Rotate
 
 
 
31
  rotate_angle = st.sidebar.slider("Rotate Image (Degrees)", 0, 360, 0, 15)
 
 
 
 
32
 
33
+ # Crop Tool
34
+ st.sidebar.subheader("Crop Tool")
35
+ crop_active = st.sidebar.checkbox("Enable Cropping")
36
+ if crop_active:
37
+ st.sidebar.text("Select Crop Bounds:")
38
+ crop_left = st.sidebar.slider("Left", 0, image.width, 0)
39
+ crop_top = st.sidebar.slider("Top", 0, image.height, 0)
40
+ crop_right = st.sidebar.slider("Right", 0, image.width, image.width)
41
+ crop_bottom = st.sidebar.slider("Bottom", 0, image.height, image.height)
42
 
43
+ # Flip Options
44
+ st.sidebar.subheader("Flip")
45
+ flip_horizontal = st.sidebar.checkbox("Flip Horizontally")
46
+ flip_vertical = st.sidebar.checkbox("Flip Vertically")
47
 
48
+ # Apply Filters
49
  if grayscale:
50
  edited_image = edited_image.convert("L")
51
 
 
54
  edited_image = edited_image.convert("RGB")
55
  enhancer = ImageEnhance.Brightness(edited_image)
56
  edited_image = enhancer.enhance(brightness)
57
+
58
+ if color != 1.0:
 
 
 
 
 
 
59
  if edited_image.mode != "RGB":
60
  edited_image = edited_image.convert("RGB")
61
+ enhancer = ImageEnhance.Color(edited_image)
62
+ edited_image = enhancer.enhance(color)
63
+
64
  if rotate_angle != 0:
65
  edited_image = edited_image.rotate(rotate_angle)
66
 
67
+ if crop_active and crop_left < crop_right and crop_top < crop_bottom:
68
+ edited_image = edited_image.crop((crop_left, crop_top, crop_right, crop_bottom))
69
+
70
  if flip_horizontal:
71
  edited_image = edited_image.transpose(Image.FLIP_LEFT_RIGHT)
72
 
73
  if flip_vertical:
74
  edited_image = edited_image.transpose(Image.FLIP_TOP_BOTTOM)
75
 
76
+ # Display the edited image
77
+ st.subheader("Edited Image")
78
+ st.image(edited_image, caption="Preview of Edited Image", use_column_width=True)
 
79
 
80
  # Download button
81
  st.sidebar.subheader("Download")