File size: 986 Bytes
b245327
 
4650f40
222f9a3
fef6a07
b245327
f953e00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28157ff
f953e00
 
b801442
c8e4656
f953e00
eb59bea
b801442
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
import gradio as gr
import numpy as np
import zipfile
from PIL import Image
import tempfile

def split_image(image):
    im = Image.fromarray(np.uint8(image))

    # Obtiene las dimensiones de la imagen
    width, height = im.size

    # Divide la imagen en 9 imágenes más pequeñas
    for i in range(3):
        for j in range(3):
            box = (j*width/3, i*height/3, (j+1)*width/3, (i+1)*height/3)
            region = im.crop(box)
            region = region.convert("RGB")
            region = region.resize((512, 512), Image.ANTIALIAS)

            with tempfile.NamedTemporaryFile(suffix='.jpg') as temp:
                region.save(temp.name)
                with zipfile.ZipFile("image.zip", 'w') as zip:
                    zip.write(temp.name)
    return "image.zip"

gr.Interface(fn=split_image,
             inputs="image",
             outputs="file",
             title="Convert collage to images",
             examples = ["example.jpg"]  
            ).launch();