Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
# Supported formats
|
| 6 |
+
formats = ['JPEG', 'PNG', 'BMP', 'GIF', 'TIFF']
|
| 7 |
+
|
| 8 |
+
st.title("Image Format Converter")
|
| 9 |
+
|
| 10 |
+
# Upload an image file
|
| 11 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff"])
|
| 12 |
+
|
| 13 |
+
if uploaded_file is not None:
|
| 14 |
+
# Open the image
|
| 15 |
+
image = Image.open(uploaded_file)
|
| 16 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 17 |
+
|
| 18 |
+
# Select the format to convert to
|
| 19 |
+
st.write("Select the format to convert to:")
|
| 20 |
+
format_to_convert = st.selectbox("Format", formats)
|
| 21 |
+
|
| 22 |
+
if st.button("Convert"):
|
| 23 |
+
# Convert the image
|
| 24 |
+
img_byte_arr = io.BytesIO()
|
| 25 |
+
image.save(img_byte_arr, format=format_to_convert)
|
| 26 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 27 |
+
|
| 28 |
+
# Provide a download link
|
| 29 |
+
st.write("Conversion Successful!")
|
| 30 |
+
st.download_button(
|
| 31 |
+
label="Download converted image",
|
| 32 |
+
data=img_byte_arr,
|
| 33 |
+
file_name=f"converted_image.{format_to_convert.lower()}",
|
| 34 |
+
mime=f"image/{format_to_convert.lower()}"
|
| 35 |
+
)
|