File size: 1,896 Bytes
d8237e6
 
6f76902
d8237e6
0fdf15f
 
b9a33c4
 
67bbbbc
 
b9a33c4
 
 
d8237e6
b9a33c4
 
00111e4
b9a33c4
 
6f76902
b9a33c4
 
 
 
 
 
 
d8237e6
 
b9a33c4
 
d8237e6
02c7e8f
d8237e6
b9a33c4
 
d8237e6
b9a33c4
009280d
b9a33c4
 
d8237e6
 
 
 
4b959ff
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
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from PIL import Image
import os

gr.themes.Soft()

# Ambil daftar format gambar yang didukung oleh Pillow
supported_formats = [data for data in (sorted(Image.SAVE.keys()) or ['BLP', 'BMP', 'BUFR', 'DDS', 'DIB', 'EPS',
                                                  'GIF', 'GRIB', 'HDF5', 'ICNS', 'ICO', 'IM',
                                                  'JPEG', 'JPEG2000', 'MPO', 'MSP', 'PALM', 'PCX',
                                                  'PDF', 'PNG', 'PPM', 'SGI', 'SPIDER', 'TGA', 'TIFF',
                                                  'WEBP', 'WMX', 'XBM']) if data not in ['BLP', 'BUFR', 'GRIB', 'HDF5', 'MSP', 'PALM', 'WMV', 'XBM']]
def convert_image(image, target_format):
    try:
        # Buka file gambar
        img = Image.open(image)

        # Ambil nama file asli tanpa ekstensi
        base_name = os.path.splitext(os.path.basename(image))[0]
        
        # Nama file keluaran dengan awalan yang diinginkan
        output_file = f"flowly_ai_image_converter_{base_name}.{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 dengan tema kustom untuk menyembunyikan footer
interface = gr.Interface(
    fn=convert_image,
    inputs=[
        gr.Image(label="Upload Image", type="filepath", height=512),  # Atur tinggi gambar input
        gr.Dropdown(label="Select Target Format", choices=supported_formats)
    ],
    outputs=gr.File(label="Converted Image"),
    title="Image Format Converter",
    description="Upload an image and select any target format for conversion. Supports all formats recognized by Pillow.",
    css="footer {visibility: hidden}"
)

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