HFUsman commited on
Commit
04cc5c3
·
verified ·
1 Parent(s): 7b42bd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -2
app.py CHANGED
@@ -82,6 +82,62 @@ def add_frame(image, frame_style="Simple"):
82
  frame_width = 30
83
  image_with_frame = ImageOps.expand(image, border=frame_width, fill="blue")
84
  return image_with_frame.convert("RGBA").rotate(0, resample=Image.BICUBIC)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  # Function to convert PIL image to bytes for download
87
  def pil_to_bytes(image, format="JPEG"):
@@ -141,7 +197,10 @@ def main():
141
  border_width = st.sidebar.slider("Border Width", 1, 100, 10)
142
  image = add_border(image, border_color, border_width)
143
  elif border_option == "Frame":
144
- frame_style = st.sidebar.selectbox("Choose a frame style", ("Simple", "Ornate", "Rounded"))
 
 
 
145
  image = add_frame(image, frame_style)
146
 
147
  # Resize the filtered image for display
@@ -166,4 +225,4 @@ def main():
166
  st.download_button("Download Edited Image", img_bytes, "edited_image.jpg", "image/jpeg")
167
 
168
  if __name__ == "__main__":
169
- main()
 
82
  frame_width = 30
83
  image_with_frame = ImageOps.expand(image, border=frame_width, fill="blue")
84
  return image_with_frame.convert("RGBA").rotate(0, resample=Image.BICUBIC)
85
+ elif frame_style == "Polaroid":
86
+ # Add Polaroid-style frame (white bottom for caption)
87
+ frame_width = 40
88
+ image_with_frame = ImageOps.expand(image, border=frame_width, fill="white")
89
+ bottom_margin = Image.new('RGB', (image_with_frame.width, 50), color='white')
90
+ return Image.new('RGB', (image_with_frame.width, image_with_frame.height + bottom_margin.height), color='white').paste(image_with_frame, (0, 0)).paste(bottom_margin, (0, image_with_frame.height))
91
+ elif frame_style == "Shadow":
92
+ # Add shadow frame
93
+ frame_width = 50
94
+ shadow_image = Image.new("RGBA", (image.width + 2 * frame_width, image.height + 2 * frame_width), (0, 0, 0, 180))
95
+ shadow_image.paste(image, (frame_width, frame_width))
96
+ return shadow_image.convert("RGB")
97
+ elif frame_style == "Vintage":
98
+ # Add vintage-style frame with a distressed look (this can be more complex)
99
+ frame_width = 30
100
+ return ImageOps.expand(image, border=frame_width, fill="beige")
101
+ elif frame_style == "Filmstrip":
102
+ # Add a filmstrip frame with a perforated edge
103
+ frame_width = 60
104
+ return ImageOps.expand(image, border=frame_width, fill="black")
105
+ elif frame_style == "Double Border":
106
+ # Add a double border (one thin, one thick)
107
+ outer_width = 60
108
+ inner_width = 20
109
+ image_with_outer_border = ImageOps.expand(image, border=outer_width, fill="black")
110
+ return ImageOps.expand(image_with_outer_border, border=inner_width, fill="white")
111
+ elif frame_style == "Metallic":
112
+ # Add metallic frame (gold, silver, etc.)
113
+ frame_width = 40
114
+ return ImageOps.expand(image, border=frame_width, fill="gold")
115
+ elif frame_style == "Heart-Shaped":
116
+ # Add heart-shaped frame
117
+ image_with_frame = image.resize((450, 450)) # Adjust for better fit
118
+ return image_with_frame.convert("RGBA")
119
+ elif frame_style == "Circular":
120
+ # Add circular frame
121
+ image_with_frame = image.resize((450, 450)) # Adjust for better fit
122
+ return image_with_frame.convert("RGBA")
123
+ elif frame_style == "Wooden":
124
+ # Add wooden frame
125
+ frame_width = 50
126
+ return ImageOps.expand(image, border=frame_width, fill="saddlebrown")
127
+ elif frame_style == "Neon Glow":
128
+ # Add neon glow frame
129
+ frame_width = 50
130
+ neon_image = Image.new("RGBA", (image.width + 2 * frame_width, image.height + 2 * frame_width), (0, 255, 255, 255))
131
+ neon_image.paste(image, (frame_width, frame_width))
132
+ return neon_image.convert("RGB")
133
+ elif frame_style == "Gradient":
134
+ # Add gradient frame
135
+ frame_width = 40
136
+ return ImageOps.expand(image, border=frame_width, fill="gradient")
137
+ elif frame_style == "Geometric":
138
+ # Add geometric frame (triangles, hexagons, etc.)
139
+ frame_width = 30
140
+ return ImageOps.expand(image, border=frame_width, fill="purple")
141
 
142
  # Function to convert PIL image to bytes for download
143
  def pil_to_bytes(image, format="JPEG"):
 
197
  border_width = st.sidebar.slider("Border Width", 1, 100, 10)
198
  image = add_border(image, border_color, border_width)
199
  elif border_option == "Frame":
200
+ frame_style = st.sidebar.selectbox("Choose a frame style", (
201
+ "Simple", "Ornate", "Rounded", "Polaroid", "Shadow", "Vintage", "Filmstrip", "Double Border", "Metallic",
202
+ "Heart-Shaped", "Circular", "Wooden", "Neon Glow", "Gradient", "Geometric"
203
+ ))
204
  image = add_frame(image, frame_style)
205
 
206
  # Resize the filtered image for display
 
225
  st.download_button("Download Edited Image", img_bytes, "edited_image.jpg", "image/jpeg")
226
 
227
  if __name__ == "__main__":
228
+ main()