server/images: use white background for non-transparent images
This commit is contained in:
parent
64c5eec3d2
commit
4220ae708d
2 changed files with 8 additions and 4 deletions
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
Reference in a new issue