Add server
This commit is contained in:
parent
9e98336d10
commit
b4bd9756fb
10
main.py
10
main.py
|
@ -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])
|
||||
|
12
printer.py
12
printer.py
|
@ -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()
|
|
@ -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}"}
|
Loading…
Reference in New Issue