diff --git a/config.sample.yaml b/config.sample.yaml index d51132e0b8be25756bf330657fdc42c1ef497c01..3d94e096a63a8f5de646ed766f101b224251ebb0 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -102,6 +102,10 @@ thumbnails: - "image/png" - "image/gif" + # Animated thumbnails can be CPU intensive to generate. To disable the generation of animated + # thumbnails, set this to false. If disabled, regular thumbnails will be returned. + allowAnimated: true + # The maximum file size to thumbnail when a capable animated thumbnail is requested. If the image # is larger than this, the thumbnail will be generated as a static image. maxAnimateSizeBytes: 10485760 # 10MB default, 0 to disable diff --git a/src/github.com/turt2live/matrix-media-repo/config/config.go b/src/github.com/turt2live/matrix-media-repo/config/config.go index 081046371386d1e9c3567252a5a25b1d6024901c..3851d52b2eb23f7c574ef872c15f3a0079f81efc 100644 --- a/src/github.com/turt2live/matrix-media-repo/config/config.go +++ b/src/github.com/turt2live/matrix-media-repo/config/config.go @@ -46,6 +46,7 @@ type ThumbnailsConfig struct { Types []string `yaml:"types,flow"` MaxAnimateSizeBytes int64 `yaml:"maxAnimateSizeBytes"` Sizes []*ThumbnailSize `yaml:"sizes,flow"` + AllowAnimated bool `yaml:"allowAnimated"` } type ThumbnailSize struct { @@ -159,6 +160,7 @@ func NewDefaultConfig() *MediaRepoConfig { MaxSourceBytes: 10485760, // 10mb MaxAnimateSizeBytes: 10485760, // 10mb NumWorkers: 10, + AllowAnimated: true, Sizes: []*ThumbnailSize{ {32, 32}, {96, 96}, diff --git a/src/github.com/turt2live/matrix-media-repo/services/thumbnail_service/thumbnailer.go b/src/github.com/turt2live/matrix-media-repo/services/thumbnail_service/thumbnailer.go index d95881e1e5aae035b2b4708b812874f18c069601..dfaa280892ca7b90c702f530c8c7e37a0767f829 100644 --- a/src/github.com/turt2live/matrix-media-repo/services/thumbnail_service/thumbnailer.go +++ b/src/github.com/turt2live/matrix-media-repo/services/thumbnail_service/thumbnailer.go @@ -12,6 +12,7 @@ import ( "github.com/disintegration/imaging" "github.com/sirupsen/logrus" + "github.com/turt2live/matrix-media-repo/config" "github.com/turt2live/matrix-media-repo/storage" "github.com/turt2live/matrix-media-repo/types" "github.com/turt2live/matrix-media-repo/util" @@ -85,7 +86,7 @@ func (t *thumbnailer) GenerateThumbnail(media *types.Media, width int, height in contentType := "image/png" imgData := &bytes.Buffer{} - if animated && util.ArrayContains(animatedTypes, media.ContentType) { + if config.Get().Thumbnails.AllowAnimated && animated && util.ArrayContains(animatedTypes, media.ContentType) { t.log.Info("Generating animated thumbnail") contentType = "image/gif"