from fastapi import APIRouter import random from api.skylight import create_image,overlay_images import os tendentRouter = APIRouter() @tendentRouter.post("/tendentest") def read_root(client_message :str = "心想事成"): pic_num = random.randint(0,19) # 產生 text_img_output_path = f"{os.path.split(os.path.abspath('main.py'))[0]}/static/tendents/vertical_chinese_text_{pic_num}.png" create_image(client_message, text_img_output_path) print(f"save to {text_img_output_path}") output_path = f"{os.path.split(os.path.abspath('main.py'))[0]}/static/tendents/combined_image_{pic_num}.png" try: os.remove(output_path) except OSError as e: print('Delete Problem: ', e) # 執行疊加 overlay_images(f"{os.path.split(os.path.abspath('main.py'))[0]}/static/tendentest.png", text_img_output_path, output_path) url = f"static/tendents/combined_image_{pic_num}.webp" return {"state":"success","url": url }