server/images: use white background for non-transparent images

This commit is contained in:
Eva 2023-05-18 11:33:19 +02:00
parent 64c5eec3d2
commit 4220ae708d
2 changed files with 8 additions and 4 deletions

View file

@ -41,7 +41,7 @@ class Image:
def frames(self) -> int: def frames(self) -> int:
return self.info["streams"][0]["nb_read_frames"] 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_greater = self.width > self.height
width, height = (-1, height) if width_greater else (width, -1) width, height = (-1, height) if width_greater else (width, -1)
@ -50,8 +50,12 @@ class Image:
"{path}", "{path}",
"-f", "-f",
"image2", "image2",
"-filter:v", "-filter_complex",
"format={pixel_format},scale={width}:{height}:flags=bicubic".format(pixel_format=pixel_format, width=width, height=height), (
"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", "-map",
"0:v:0", "0:v:0",
"-vframes", "-vframes",

View file

@ -689,7 +689,7 @@ def generate_post_thumbnail(post: model.Post) -> None:
image.resize_fill( image.resize_fill(
int(config.config["thumbnails"]["post_width"]), int(config.config["thumbnails"]["post_width"]),
int(config.config["thumbnails"]["post_height"]), int(config.config["thumbnails"]["post_height"]),
"rgb24", keep_transparency=False,
) )
files.save(get_post_thumbnail_path(post), image.to_jpeg()) files.save(get_post_thumbnail_path(post), image.to_jpeg())
except errors.ProcessingError: except errors.ProcessingError: