mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 09:52:26 -05:00
[feature] media: add webp support (#1155)
* media: add webp support Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> * bump exif-terminator to v0.5.0 Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
This commit is contained in:
parent
f9e5ec99bd
commit
1a3f26fb5c
26 changed files with 4348 additions and 19 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
"github.com/buckket/go-blurhash"
|
||||
"github.com/disintegration/imaging"
|
||||
_ "golang.org/x/image/webp" // blank import to support WebP decoding
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -71,7 +72,7 @@ func decodeImage(r io.Reader, contentType string) (*imageMeta, error) {
|
|||
var err error
|
||||
|
||||
switch contentType {
|
||||
case mimeImageJpeg:
|
||||
case mimeImageJpeg, mimeImageWebp:
|
||||
i, err = imaging.Decode(r, imaging.AutoOrientation(true))
|
||||
case mimeImagePng:
|
||||
strippedPngReader := io.Reader(&PNGAncillaryChunkStripper{
|
||||
|
|
@ -104,7 +105,7 @@ func decodeImage(r io.Reader, contentType string) (*imageMeta, error) {
|
|||
}
|
||||
|
||||
// deriveThumbnail returns a byte slice and metadata for a thumbnail
|
||||
// of a given jpeg, png, or gif, or an error if something goes wrong.
|
||||
// of a given jpeg, png, gif or webp, or an error if something goes wrong.
|
||||
//
|
||||
// If createBlurhash is true, then a blurhash will also be generated from a tiny
|
||||
// version of the image. This costs precious CPU cycles, so only use it if you
|
||||
|
|
@ -117,7 +118,7 @@ func deriveThumbnail(r io.Reader, contentType string, createBlurhash bool) (*ima
|
|||
var err error
|
||||
|
||||
switch contentType {
|
||||
case mimeImageJpeg, mimeImageGif:
|
||||
case mimeImageJpeg, mimeImageGif, mimeImageWebp:
|
||||
i, err = imaging.Decode(r, imaging.AutoOrientation(true))
|
||||
case mimeImagePng:
|
||||
strippedPngReader := io.Reader(&PNGAncillaryChunkStripper{
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ func (p *ProcessingMedia) loadFullSize(ctx context.Context) error {
|
|||
// decode the image
|
||||
ct := p.attachment.File.ContentType
|
||||
switch ct {
|
||||
case mimeImageJpeg, mimeImagePng:
|
||||
case mimeImageJpeg, mimeImagePng, mimeImageWebp:
|
||||
decoded, err = decodeImage(stored, ct)
|
||||
case mimeImageGif:
|
||||
decoded, err = decodeGif(stored)
|
||||
|
|
@ -319,7 +319,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
|
|||
p.attachment.Type = gtsmodel.FileTypeImage
|
||||
// nothing to terminate, we can just store the multireader
|
||||
readerToStore = multiReader
|
||||
case mimeJpeg, mimePng:
|
||||
case mimeJpeg, mimePng, mimeWebp:
|
||||
p.attachment.Type = gtsmodel.FileTypeImage
|
||||
if fileSize > 0 {
|
||||
terminated, err := terminator.Terminate(multiReader, int(fileSize), extension)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ const (
|
|||
|
||||
mimePng = "png"
|
||||
mimeImagePng = mimeImage + "/" + mimePng
|
||||
|
||||
mimeWebp = "webp"
|
||||
mimeImageWebp = mimeImage + "/" + mimeWebp
|
||||
)
|
||||
|
||||
type processState int32
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ func AllSupportedMIMETypes() []string {
|
|||
mimeImageJpeg,
|
||||
mimeImageGif,
|
||||
mimeImagePng,
|
||||
mimeImageWebp,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ func supportedImage(mimeType string) bool {
|
|||
mimeImageJpeg,
|
||||
mimeImageGif,
|
||||
mimeImagePng,
|
||||
mimeImageWebp,
|
||||
}
|
||||
for _, accepted := range acceptedImageTypes {
|
||||
if mimeType == accepted {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue