| from fastapi import FastAPI, UploadFile, Form |
| from fastapi.responses import FileResponse |
| import os, shutil |
|
|
| from image.qr import generate_qr |
| from image.watermark import add_qr_to_background |
|
|
| app = FastAPI() |
|
|
| TEMP_DIR = "temp" |
| os.makedirs(TEMP_DIR, exist_ok=True) |
|
|
| @app.post("/background") |
| async def create_background( |
| file: UploadFile, |
| premium: bool = Form(False) |
| ): |
| input_path = f"{TEMP_DIR}/input.png" |
| output_path = f"{TEMP_DIR}/output.png" |
|
|
| with open(input_path, "wb") as f: |
| f.write(await file.read()) |
|
|
| if premium: |
| shutil.copy(input_path, output_path) |
| else: |
| qr = generate_qr("https://cloudfom.org") |
| add_qr_to_background(input_path, output_path, qr) |
|
|
| return FileResponse(output_path, media_type="image/png") |
|
|