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:
parent
80840b9509
commit
64c5eec3d2
2 changed files with 3 additions and 2 deletions
|
@ -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) -> None:
|
def resize_fill(self, width: int, height: int, pixel_format: str = "rgb32") -> 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)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class Image:
|
||||||
"-f",
|
"-f",
|
||||||
"image2",
|
"image2",
|
||||||
"-filter:v",
|
"-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",
|
"-map",
|
||||||
"0:v:0",
|
"0:v:0",
|
||||||
"-vframes",
|
"-vframes",
|
||||||
|
|
|
@ -689,6 +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",
|
||||||
)
|
)
|
||||||
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:
|
||||||
|
|
Reference in a new issue