Update handler.py
Browse files- handler.py +8 -43
handler.py
CHANGED
|
@@ -1,53 +1,18 @@
|
|
| 1 |
from typing import Dict, Any
|
| 2 |
from PIL import Image, ImageDraw
|
| 3 |
-
|
| 4 |
-
import requests
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
class EndpointHandler():
|
| 8 |
def __init__(self, path=''):
|
| 9 |
-
# No cargamos ning煤n modelo pesado para esta prueba
|
| 10 |
pass
|
| 11 |
|
| 12 |
def __call__(self, data: Dict[str, Any]):
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
image = image_src
|
| 21 |
-
# Caso B: Es una URL o Ruta
|
| 22 |
-
elif isinstance(image_src, str):
|
| 23 |
-
if image_src.startswith('http'):
|
| 24 |
-
image = Image.open(BytesIO(requests.get(image_src).content))
|
| 25 |
-
elif os.path.exists(image_src):
|
| 26 |
-
image = Image.open(image_src)
|
| 27 |
-
else:
|
| 28 |
-
# Es una cadena de bytes (base64 decodeada string?)
|
| 29 |
-
pass
|
| 30 |
-
# Caso C: Son bytes crudos
|
| 31 |
-
else:
|
| 32 |
-
image = Image.open(BytesIO(image_src))
|
| 33 |
-
except Exception as e:
|
| 34 |
-
# Si falla la lectura, creamos una imagen de ERROR con texto
|
| 35 |
-
img_err = Image.new('RGB', (500, 500), color='yellow')
|
| 36 |
-
return img_err
|
| 37 |
-
|
| 38 |
-
if not image:
|
| 39 |
-
# Si no se pudo cargar, devolvemos imagen AZUL (Diagn贸stico)
|
| 40 |
-
return Image.new('RGB', (500, 500), color='blue')
|
| 41 |
-
|
| 42 |
-
# 2. Si la imagen se ley贸 bien, la convertimos a RGB
|
| 43 |
-
image = image.convert("RGB")
|
| 44 |
-
|
| 45 |
-
# 3. DIBUJAR UN CUADRO ROJO EN EL CENTRO
|
| 46 |
-
# Esto nos confirma que el servidor manipul贸 la imagen
|
| 47 |
-
draw = ImageDraw.Draw(image)
|
| 48 |
-
w, h = image.size
|
| 49 |
-
# Cuadro rojo de 100x100 en el centro
|
| 50 |
-
draw.rectangle([w//2 - 50, h//2 - 50, w//2 + 50, h//2 + 50], fill="red", outline="white")
|
| 51 |
|
| 52 |
-
|
| 53 |
-
return image
|
|
|
|
| 1 |
from typing import Dict, Any
|
| 2 |
from PIL import Image, ImageDraw
|
| 3 |
+
import io
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class EndpointHandler():
|
| 6 |
def __init__(self, path=''):
|
|
|
|
| 7 |
pass
|
| 8 |
|
| 9 |
def __call__(self, data: Dict[str, Any]):
|
| 10 |
+
# IGNORAMOS la entrada.
|
| 11 |
+
# Creamos una imagen VERDE de 800x800 desde cero.
|
| 12 |
+
img = Image.new('RGB', (800, 800), color=(0, 255, 0)) # Verde Brillante
|
| 13 |
|
| 14 |
+
# Le escribimos un texto o dibujamos un c铆rculo azul para confirmar
|
| 15 |
+
draw = ImageDraw.Draw(img)
|
| 16 |
+
draw.ellipse((200, 200, 600, 600), fill=(0, 0, 255)) # C铆rculo Azul
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
return img
|
|
|