File size: 1,126 Bytes
9c8cc18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()}"
        )