From 64c5eec3d2c57862a6ce83401acdd21b8debafe3 Mon Sep 17 00:00:00 2001 From: Eva Date: Thu, 18 May 2023 11:08:44 +0200 Subject: [PATCH] server/images: resize images in rgb, explicitly use bicubic Indexed color PNGs would use their palette during scaling, leading to very ugly dithering. Convert to RGB32/RGB24, depending on if we intend to keep transparency. For RGB24 this sets background color from the palette if there was one, black otherwise although that may be undesirable. Will have to find a way to fall back to a nicer color, or always use the same color that we configure ourselves. --- server/szurubooru/func/images.py | 4 ++-- server/szurubooru/func/posts.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index e28520dd..7daf46ff 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -41,7 +41,7 @@ class Image: def frames(self) -> int: return self.info["streams"][0]["nb_read_frames"] - def resize_fill(self, width: int, height: int) -> None: + def resize_fill(self, width: int, height: int, pixel_format: str = "rgb32") -> None: width_greater = self.width > self.height width, height = (-1, height) if width_greater else (width, -1) @@ -51,7 +51,7 @@ class Image: "-f", "image2", "-filter:v", - "scale='{width}:{height}'".format(width=width, height=height), + "format={pixel_format},scale={width}:{height}:flags=bicubic".format(pixel_format=pixel_format, width=width, height=height), "-map", "0:v:0", "-vframes", diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index be2259cf..e165fd03 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -689,6 +689,7 @@ def generate_post_thumbnail(post: model.Post) -> None: image.resize_fill( int(config.config["thumbnails"]["post_width"]), int(config.config["thumbnails"]["post_height"]), + "rgb24", ) files.save(get_post_thumbnail_path(post), image.to_jpeg()) except errors.ProcessingError: