diff --git a/CHANGELOG.md b/CHANGELOG.md index 699727652dc17aa3537f5a6a3c74e91dd7b5fbab..b39eddb0d4d9fc1cc53af6885deaf46877359564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ path/server, for example, then you can simply update the path in the config for * Support for [MSC4034](https://github.com/matrix-org/matrix-spec-proposals/pull/4034) (self-serve usage information) is added, alongside a new "maximum file count" quota limit. * The `GET /_synapse/admin/v1/statistics/users/media` [endpoint](https://matrix-org.github.io/synapse/v1.88/admin_api/statistics.html#users-media-usage-statistics) from Synapse is now supported at the same path for local server admins. * Thumbnailing support for BMP images. +* Thumbnailing support for TIFF images. ### Removed diff --git a/config.sample.yaml b/config.sample.yaml index 2da60529e43a3dc5b5de23261fbfb0f697e61f39..62d51557242b6c6b31571fb722a0ea59f63b5ae4 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -412,6 +412,7 @@ thumbnails: - "image/heif" - "image/webp" - "image/bmp" + - "image/tiff" #- "image/svg+xml" # Be sure to have ImageMagick installed to thumbnail SVG files - "audio/mpeg" - "audio/ogg" diff --git a/thumbnailing/i/tiff.go b/thumbnailing/i/tiff.go new file mode 100644 index 0000000000000000000000000000000000000000..57334e59ae4b5eeb1f5ca095f333c4a63d5e6618 --- /dev/null +++ b/thumbnailing/i/tiff.go @@ -0,0 +1,46 @@ +package i + +import ( + "errors" + "io" + + "github.com/turt2live/matrix-media-repo/common/rcontext" + "github.com/turt2live/matrix-media-repo/thumbnailing/m" + "golang.org/x/image/tiff" +) + +type tiffGenerator struct { +} + +func (d tiffGenerator) supportedContentTypes() []string { + return []string{"image/tiff"} +} + +func (d tiffGenerator) supportsAnimation() bool { + return false +} + +func (d tiffGenerator) matches(img io.Reader, contentType string) bool { + return contentType == "image/tiff" +} + +func (d tiffGenerator) GetOriginDimensions(b io.Reader, contentType string, ctx rcontext.RequestContext) (bool, int, int, error) { + i, err := tiff.DecodeConfig(b) + if err != nil { + return false, 0, 0, err + } + return true, i.Width, i.Height, nil +} + +func (d tiffGenerator) GenerateThumbnail(b io.Reader, contentType string, width int, height int, method string, animated bool, ctx rcontext.RequestContext) (*m.Thumbnail, error) { + src, err := tiff.Decode(b) + if err != nil { + return nil, errors.New("tiff: error decoding thumbnail: " + err.Error()) + } + + return pngGenerator{}.GenerateThumbnailOf(src, width, height, method, ctx) +} + +func init() { + generators = append(generators, tiffGenerator{}) +}