WebtoPng / app.py
razaAhmed's picture
Create app.py
4b0d17b
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()