File size: 774 Bytes
3b8ad4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")