Update routers/memoriam.py
Browse files- routers/memoriam.py +9 -3
routers/memoriam.py
CHANGED
@@ -8,10 +8,16 @@ from typing import Optional
|
|
8 |
router = APIRouter()
|
9 |
|
10 |
def download_image_from_url(url: str) -> Image.Image:
|
11 |
-
|
|
|
|
|
|
|
12 |
if response.status_code != 200:
|
13 |
-
raise HTTPException(status_code=400, detail="Imagem n茫o p么de ser baixada.")
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
def resize_and_crop_to_fill(img: Image.Image, target_width: int, target_height: int) -> Image.Image:
|
17 |
img_ratio = img.width / img.height
|
|
|
8 |
router = APIRouter()
|
9 |
|
10 |
def download_image_from_url(url: str) -> Image.Image:
|
11 |
+
headers = {
|
12 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
|
13 |
+
}
|
14 |
+
response = requests.get(url, headers=headers)
|
15 |
if response.status_code != 200:
|
16 |
+
raise HTTPException(status_code=400, detail=f"Imagem n茫o p么de ser baixada. C贸digo {response.status_code}")
|
17 |
+
try:
|
18 |
+
return Image.open(BytesIO(response.content)).convert("RGB")
|
19 |
+
except Exception as e:
|
20 |
+
raise HTTPException(status_code=400, detail=f"Erro ao abrir imagem: {str(e)}")
|
21 |
|
22 |
def resize_and_crop_to_fill(img: Image.Image, target_width: int, target_height: int) -> Image.Image:
|
23 |
img_ratio = img.width / img.height
|