Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -9,23 +9,10 @@ app = FastAPI()
9
  def greet_json():
10
  return {"Hello": "World!"}
11
 
12
-
13
- @app.post("/generate-image")
14
- async def generate_image(text: str = Form(...)):
 
 
 
15
  # Create a blank image
16
- image = Image.new('RGB', (512, 256), color=(73, 109, 137))
17
- draw = ImageDraw.Draw(image)
18
-
19
- # Use a default font
20
- try:
21
- font = ImageFont.truetype("arial.ttf", 30)
22
- except:
23
- font = ImageFont.load_default()
24
-
25
- draw.text((10, 100), text, fill=(255, 255, 255), font=font)
26
-
27
- # Convert image to bytes
28
- buf = io.BytesIO()
29
- image.save(buf, format="PNG")
30
- buf.seek(0)
31
- return StreamingResponse(buf, media_type="image/png")
 
9
  def greet_json():
10
  return {"Hello": "World!"}
11
 
12
+ @app.get("/get-image")
13
+ async def get_image(filename: str):
14
+ image_path = f"static/{filename}"
15
+ if not os.path.exists(image_path):
16
+ return {"error": "Image not found"}
17
+ return FileResponse(image_path, media_type="image/png", filename=filename)
18
  # Create a blank image