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.
This commit is contained in:
Eva 2023-05-18 11:08:44 +02:00
parent 80840b9509
commit 64c5eec3d2
2 changed files with 3 additions and 2 deletions

View file

@ -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",

View file

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