-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |