Spaces:
Runtime error
Runtime error
File size: 1,096 Bytes
b8cdc48 b245327 4650f40 222f9a3 fef6a07 b245327 f953e00 b10993d d5928ad df65e84 d5928ad e690df3 d5928ad e690df3 b10993d 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 33 34 35 |
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
with zipfile.ZipFile("images.zip", 'w') as zip:
# 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((width//3, height//3), Image.ANTIALIAS)
with tempfile.NamedTemporaryFile(suffix='.png') as temp:
region.save(temp.name)
zip.write(temp.name)
temp.flush()
temp.close()
return "images.zip"
gr.Interface(fn=split_image,
inputs="image",
outputs="file",
title="Convert collage to images",
examples = ["example.jpg"]
).launch(); |