From f180077f0a2a77266bc61d1f3ee55a38fd309471 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 5 Dec 2024 19:47:39 +0200 Subject: [PATCH] media: generate blurhashes for video thumbnails --- pkg/gomuks/media.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/gomuks/media.go b/pkg/gomuks/media.go index 0654c57..01e7637 100644 --- a/pkg/gomuks/media.go +++ b/pkg/gomuks/media.go @@ -570,12 +570,18 @@ func (gmx *Gomuks) generateVideoThumbnail(ctx context.Context, filePath string, if err != nil { return fmt.Errorf("failed to seek to start of file: %w", err) } - cfg, _, err := image.DecodeConfig(tempFile) + img, _, err := image.Decode(tempFile) if err != nil { zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to decode thumbnail image config") } else { - thumbnailInfo.Width = cfg.Width - thumbnailInfo.Height = cfg.Height + bounds := img.Bounds() + thumbnailInfo.Width = bounds.Dx() + thumbnailInfo.Height = bounds.Dy() + hash, err := blurhash.Encode(4, 3, img) + if err != nil { + zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to generate image blurhash") + } + thumbnailInfo.AnoaBlurhash = hash } _ = tempFile.Close() checksum := hasher.Sum(nil)