diff options
author | 2022-01-09 18:41:22 +0100 | |
---|---|---|
committer | 2022-01-09 18:41:22 +0100 | |
commit | dccf21dd87638320a687a0556c973cced541c945 (patch) | |
tree | 03dd737e3d44bdad52b6a2ac2f1e78ec876d2ba1 /internal/media/image.go | |
parent | compiling now (diff) | |
download | gotosocial-dccf21dd87638320a687a0556c973cced541c945.tar.xz |
tests are passing, but there's still much to be done
Diffstat (limited to 'internal/media/image.go')
-rw-r--r-- | internal/media/image.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/internal/media/image.go b/internal/media/image.go index acc62a28b..4c0b28c02 100644 --- a/internal/media/image.go +++ b/internal/media/image.go @@ -108,7 +108,7 @@ func decodeImage(b []byte, contentType string) (*ImageMeta, error) { // // Note that the aspect ratio of the image will be retained, // so it will not necessarily be a square, even if x and y are set as the same value. -func deriveThumbnail(b []byte, contentType string) (*ImageMeta, error) { +func deriveThumbnail(b []byte, contentType string, createBlurhash bool) (*ImageMeta, error) { var i image.Image var err error @@ -138,10 +138,20 @@ func deriveThumbnail(b []byte, contentType string) (*ImageMeta, error) { size := width * height aspect := float64(width) / float64(height) - tiny := resize.Thumbnail(32, 32, thumb, resize.NearestNeighbor) - bh, err := blurhash.Encode(4, 3, tiny) - if err != nil { - return nil, err + im := &ImageMeta{ + width: width, + height: height, + size: size, + aspect: aspect, + } + + if createBlurhash { + tiny := resize.Thumbnail(32, 32, thumb, resize.NearestNeighbor) + bh, err := blurhash.Encode(4, 3, tiny) + if err != nil { + return nil, err + } + im.blurhash = bh } out := &bytes.Buffer{} @@ -150,14 +160,10 @@ func deriveThumbnail(b []byte, contentType string) (*ImageMeta, error) { }); err != nil { return nil, err } - return &ImageMeta{ - image: out.Bytes(), - width: width, - height: height, - size: size, - aspect: aspect, - blurhash: bh, - }, nil + + im.image = out.Bytes() + + return im, nil } // deriveStaticEmojji takes a given gif or png of an emoji, decodes it, and re-encodes it as a static png. |