From c19e59de8bb2fcceb6ce8e289a2829ef49c45ed1 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Sun, 15 Oct 2023 15:16:53 +0200 Subject: [PATCH] create JPG and 8bit PNG under temporary name first, rename when done this way files only show up for download in the web interface when really fully done, and not while still being written to --- scripts/render.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/render.py b/scripts/render.py index 7dc43a9d..76c3e4a9 100755 --- a/scripts/render.py +++ b/scripts/render.py @@ -404,7 +404,8 @@ class JobRenderer(threading.Thread): img = Image.open(prefix + '.png') try: img = img.convert('RGB') - img.save(prefix + '.jpg', quality=50) + img.save(prefix + '.jpg.tmp', quality=50) + os.rename(prefix + '.jpg.tmp', prefix + '.jpg') except Exception as e: LOG.warning("PNG to JPEG conversion failed: %s" % e) img.thumbnail((200, 200), Image.ANTIALIAS) @@ -414,9 +415,10 @@ class JobRenderer(threading.Thread): img.close() try: - pngquant_cmd = [ "pngquant", "--output", "%s.8bit.png" % prefix, + pngquant_cmd = [ "pngquant", "--output", "%s.8bit.tmp" % prefix, "%s.png" % prefix ] subprocess.check_call(pngquant_cmd) + os.rename(prefix + '.8bit.tmp', prefix + '8bit.png') except Exception as e: LOG.warning("PNG color reduction failed: %s" % e)