import streamlit as st from PIL import Image import io # Supported formats formats = ['JPEG', 'PNG', 'BMP', 'GIF', 'TIFF'] st.title("Image Format Converter") # Upload an image file uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff"]) if uploaded_file is not None: # Open the image image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_column_width=True) # Select the format to convert to st.write("Select the format to convert to:") format_to_convert = st.selectbox("Format", formats) if st.button("Convert"): # Convert the image img_byte_arr = io.BytesIO() image.save(img_byte_arr, format=format_to_convert) img_byte_arr = img_byte_arr.getvalue() # Provide a download link st.write("Conversion Successful!") st.download_button( label="Download converted image", data=img_byte_arr, file_name=f"converted_image.{format_to_convert.lower()}", mime=f"image/{format_to_convert.lower()}" )