File size: 1,065 Bytes
d8237e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image

# Ambil daftar format gambar yang didukung oleh Pillow
supported_formats = sorted(Image.SAVE.keys())

def convert_image(image, target_format):
    try:
        # Buka file gambar
        img = Image.open(image)

        # Nama file keluaran
        output_file = f"converted_image.{target_format.lower()}"
        
        # Simpan gambar dalam format yang dipilih
        img.save(output_file, format=target_format.upper())
        
        return output_file
    except Exception as e:
        return f"Error: {e}"

# Antarmuka Gradio
interface = gr.Interface(
    fn=convert_image,
    inputs=[
        gr.Image(label="Upload Image", type="file"),
        gr.Dropdown(label="Select Target Format", choices=supported_formats)
    ],
    outputs=gr.File(label="Converted Image"),
    title="Universal Image Format Converter",
    description="Upload an image and select any target format for conversion. Supports all formats recognized by Pillow."
)

# Jalankan aplikasi
if __name__ == "__main__":
    interface.launch()