diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-19 05:08:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-19 05:08:19 +0000 |
commit | cd719b08bdb818b7e300f200aece24118386e50a (patch) | |
tree | 27e897c59e18bb10bba451f96bdc2d3cbd3c26f3 /modules/api | |
parent | 90e560bb7583c16f2595e6f62faeb7934e66edce (diff) | |
parent | 4760c3c0b58059e9c655a6ea8360c65a4586a71b (diff) | |
download | stable-diffusion-webui-gfx803-cd719b08bdb818b7e300f200aece24118386e50a.tar.gz stable-diffusion-webui-gfx803-cd719b08bdb818b7e300f200aece24118386e50a.tar.bz2 stable-diffusion-webui-gfx803-cd719b08bdb818b7e300f200aece24118386e50a.zip |
Merge pull request #12663 from SpenserCai/get_image_from_url
api support get image from url
Diffstat (limited to 'modules/api')
-rw-r--r-- | modules/api/api.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/api/api.py b/modules/api/api.py index fb2c2ce9..4abfd9bd 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -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: |