Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Implement harsh image compression on save
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbricman committed Oct 1, 2021
1 parent 5f2de61 commit 252372b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import secrets
from pathlib import Path
from typing import Optional
from PIL import Image
import io

from util import *
from responses import *
Expand Down Expand Up @@ -39,10 +41,9 @@ async def save_language(content: str, background_tasks: BackgroundTasks):
@app.post('/save/imag')
async def save_imagery(file: UploadFile = File(...)):
content = await file.read()
extension = Path(file.filename).suffix
filename = 'conceptarium/' + \
secrets.token_urlsafe(8) + extension
open(filename, 'wb+').write(content)
image = Image.open(io.BytesIO(content)).convert('RGB')
filename = 'conceptarium/' + secrets.token_urlsafe(8) + '.jpg'
image.save(filename, quality=50)
save(Thought(filename, content, model))
return HTMLResponse(save_success_response())

Expand Down

0 comments on commit 252372b

Please sign in to comment.