diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-02-16 16:11:17 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-02-16 16:11:23 +0000 |
commit | 063e65d860b82bd006b5df52efd241edb4e4ca54 (patch) | |
tree | aae0a00427d783de7c492a20b345c46442dfa831 | |
parent | c24921952a69e28b3786e61e1869cff136846bbf (diff) | |
download | netsurf-test-063e65d860b82bd006b5df52efd241edb4e4ca54.tar.gz netsurf-test-063e65d860b82bd006b5df52efd241edb4e4ca54.tar.bz2 |
Buffer the icon save
-rwxr-xr-x | cgi-bin/image.cgi | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cgi-bin/image.cgi b/cgi-bin/image.cgi index 3f58abc..edcca1e 100755 --- a/cgi-bin/image.cgi +++ b/cgi-bin/image.cgi @@ -6,7 +6,7 @@ import sys cgitb.enable() import os -from base64 import b64decode +from io import BytesIO auth = os.getenv("HTTP_AUTHORIZATION") query = os.getenv("QUERY_STRING") or "" @@ -30,6 +30,9 @@ except: width = width if width > 0 else 100 height = height if height > 0 else 100 +width = width if width < 4000 else 4000 +height = height if height < 4000 else 4000 + FORMATS = { "png": { "ctype": "image/png", "ptype": "png" }, "jpeg": { "ctype": "image/jpeg", "ptype": "jpeg" }, @@ -52,4 +55,8 @@ im.putdata([(255,0,0)] * (width * height)) print("Content-Type: {}".format(fmt["ctype"])) print("") sys.stdout.flush() -im.save(fp=sys.stdout.buffer, format=fmt["ptype"]) + +imgbytes = BytesIO() +im.save(fp=imgbytes, format=fmt["ptype"]) + +sys.stdout.buffer.write(imgbytes.getvalue()) |