Skip to content

Commit

Permalink
Add TIFF thumbnail support
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Aug 2, 2023
1 parent f9ff53d commit 84e2186
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
46 changes: 46 additions & 0 deletions thumbnailing/i/tiff.go
Original file line number Diff line number Diff line change
@@ -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{})
}

0 comments on commit 84e2186

Please sign in to comment.