Add server

This commit is contained in:
jimmy 2022-11-05 00:41:07 +13:00
parent 9e98336d10
commit b4bd9756fb
3 changed files with 23 additions and 18 deletions

10
main.py
View File

@ -1,10 +0,0 @@
from watchgod import watch
from printer import printer
base = "./"
def main():
for changes in watch('./images'):
print(changes)
for change in changes:
printer(base + "/" + change[1])

View File

@ -3,18 +3,14 @@ from PIL import Image, ImageDraw, ImageFont, ImageOps
import textwrap
import random
def printer(path):
#432x432
#34 34
432/48
def printer():
fr=Image.open("frame.png")
im=Image.open(path)
im=Image.open("image.png")
im = im.resize((432, 432), Image.Resampling.BOX)
fr.paste(im, (34,34), im)
fr.show()
#fr.show()
raster = StarTSPImage.imageToRaster(fr, cut=True)
@ -22,4 +18,4 @@ def printer(path):
printer.write(raster)
if __name__ == "__main__":
printer("./images/test.png")
printer()

19
server.py Normal file
View File

@ -0,0 +1,19 @@
from fastapi import FastAPI, File, UploadFile
from printer import printer
app = FastAPI()
@app.post("/upload")
def upload(file: UploadFile = File(...)):
try:
contents = file.file.read()
with open("image.png", 'wb') as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
printer()
return {"message": f"Successfully uploaded {file.filename}"}