razaAhmed commited on
Commit
4b0d17b
·
1 Parent(s): cc6d184

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from io import BytesIO
4
+
5
+ def main():
6
+ st.title("WEB to PNG Converter")
7
+
8
+ # Upload image through Streamlit
9
+ uploaded_file = st.file_uploader("Choose an image file", type=["webp"])
10
+
11
+ if uploaded_file is not None:
12
+ st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
13
+
14
+ # Convert image to PNG
15
+ converted_image = convert_to_png(uploaded_file)
16
+
17
+ # Display the converted image
18
+ st.image(converted_image, caption="Converted Image", use_column_width=True)
19
+
20
+ # Offer download link for the converted image
21
+ download_link(converted_image, "Download Converted Image")
22
+
23
+ def convert_to_png(image_file):
24
+ # Open the uploaded image using PIL
25
+ img = Image.open(image_file)
26
+
27
+ # Convert to PNG format
28
+ img_png = img.convert("RGBA")
29
+
30
+ return img_png
31
+
32
+ def download_link(image, text):
33
+ # Create a downloadable link for the converted image
34
+ with st.spinner("Converting..."):
35
+ img_bytes = BytesIO()
36
+ image.save(img_bytes, format="PNG")
37
+
38
+ st.download_button(
39
+ label=text,
40
+ data=img_bytes.getvalue(),
41
+ file_name="converted_image.png",
42
+ key="download_button"
43
+ )
44
+
45
+ if __name__ == "__main__":
46
+ main()