Skip to content

Commit

Permalink
Apply max pixel count to blurhashes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Aug 26, 2023
1 parent 1ff041f commit 428eab3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pipelines/_steps/upload/blurhash_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/disintegration/imaging"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/database"
"github.com/turt2live/matrix-media-repo/util/readers"
)

func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeBytes int64, sha256hash string) chan struct{} {
Expand All @@ -21,10 +22,24 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeB
if !ctx.Config.Features.MSC2448Blurhash.Enabled {
return
}

// Don't blurhash anything we wouldn't thumbnail
if ctx.Config.Thumbnails.MaxSourceBytes <= sizeBytes {
return
}

// Same goes for pixel size
var c image.Config
br := readers.NewBufferReadsReader(reader)
c, _, err = image.DecodeConfig(br)
if err != nil {
return
}
if (c.Width * c.Height) >= ctx.Config.Thumbnails.MaxPixels {
return
}
reader = br.GetRewoundReader()

var img image.Image
img, err = imaging.Decode(reader)
if err != nil {
Expand Down

0 comments on commit 428eab3

Please sign in to comment.