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
django-3.2
Hartmut Holzgraefe 2023-10-15 15:16:53 +02:00
rodzic 2569d49cd5
commit c19e59de8b
1 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -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)