Skip to content

Commit

Permalink
api support get image from url
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenserCai committed Aug 19, 2023
1 parent 541ef92 commit 4760c3c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def setUpscalers(req: dict):


def decode_base64_to_image(encoding):
if encoding.startswith("http://") or encoding.startswith("https://"):
import requests
response = requests.get(encoding, timeout=30, headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'})
try:
image = Image.open(BytesIO(response.content))
return image
except Exception as e:
raise HTTPException(status_code=500, detail="Invalid image url") from e

if encoding.startswith("data:image/"):
encoding = encoding.split(";")[1].split(",")[1]
try:
Expand Down

0 comments on commit 4760c3c

Please sign in to comment.