File size: 1,268 Bytes
cc6d184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from PIL import Image
from io import BytesIO

def main():
    st.title("WEB to PNG Converter")

    # Upload image through Streamlit
    uploaded_file = st.file_uploader("Choose an image file", type=["webp"])

    if uploaded_file is not None:
        st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)

        # Convert image to PNG
        converted_image = convert_to_png(uploaded_file)

        # Display the converted image
        st.image(converted_image, caption="Converted Image", use_column_width=True)

        # Offer download link for the converted image
        download_link(converted_image, "Download Converted Image")

def convert_to_png(image_file):
    # Open the uploaded image using PIL
    img = Image.open(image_file)

    # Convert to PNG format
    img_png = img.convert("RGBA")

    return img_png

def download_link(image, text):
    # Create a downloadable link for the converted image
    with st.spinner("Converting..."):
        img_bytes = BytesIO()
        image.save(img_bytes, format="PNG")

    st.download_button(
        label=text,
        data=img_bytes.getvalue(),
        file_name="converted_image.png",
        key="download_button"
    )

if __name__ == "__main__":
    main()