From 4220ae708de64780bc9c40826df6043c1333a99f Mon Sep 17 00:00:00 2001 From: Eva Date: Thu, 18 May 2023 11:33:19 +0200 Subject: [PATCH] server/images: use white background for non-transparent images --- server/szurubooru/func/images.py | 10 +++++++--- server/szurubooru/func/posts.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index 7daf46ff..1ea025e1 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, pixel_format: str = "rgb32") -> None: + def resize_fill(self, width: int, height: int, keep_transparency: bool = True) -> None: width_greater = self.width > self.height width, height = (-1, height) if width_greater else (width, -1) @@ -50,8 +50,12 @@ class Image: "{path}", "-f", "image2", - "-filter:v", - "format={pixel_format},scale={width}:{height}:flags=bicubic".format(pixel_format=pixel_format, width=width, height=height), + "-filter_complex", + ( + "format=rgb32,scale={width}:{height}:flags=bicubic" + if keep_transparency else + "[0:v]format=rgb32,scale={width}:{height}:flags=bicubic[a];color=white[b];[b][a]scale2ref[b][a];[b][a]overlay" + ).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 e165fd03..118807b3 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -689,7 +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", + keep_transparency=False, ) files.save(get_post_thumbnail_path(post), image.to_jpeg()) except errors.ProcessingError: