in web-app-pix2info-python/src/backend/render.py [0:0]
def prepare_rendering(demo: Demo) -> bool:
demo.rendering = False
demo.frame_count = sum(1 for _ in render_full_frames(demo))
demo.rendering = True
copy_frame = 1 < demo.frame_count and demo.options.format == ImageFormat.WEBP
if demo.options.format == ImageFormat.GIF and 1 < demo.frame_count:
# Quantize base image to 8bpp
method = Image.Quantize.MEDIANCUT.value # Best with dithering
dither = Image.Dither.FLOYDSTEINBERG # Best for real-life pictures
demo.image = demo.image.quantize(method=method, dither=dither).convert("RGB")
demo.draw = ImageDraw.Draw(demo.image, mode="RGBA")
return copy_frame