[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:
Sigrid Solveig Haflínudóttir 2022-12-06 14:15:25 +01:00 committed by GitHub
commit 1a3f26fb5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 4348 additions and 19 deletions

View file

@ -43,6 +43,8 @@ func Terminate(in io.Reader, fileSize int, mediaType string) (io.Reader, error)
switch mediaType {
case "image/jpeg", "jpeg", "jpg":
err = terminateJpeg(scanner, pipeWriter, fileSize)
case "image/webp", "webp":
err = terminateWebp(scanner, pipeWriter)
case "image/png", "png":
// for pngs we need to skip the header bytes, so read them in
// and check we're really dealing with a png here
@ -86,6 +88,18 @@ func terminateJpeg(scanner *bufio.Scanner, writer io.WriteCloser, expectedFileSi
return nil
}
func terminateWebp(scanner *bufio.Scanner, writer io.WriteCloser) error {
v := &webpVisitor{
writer: writer,
}
// use the webp visitor's 'split' function, which satisfies the bufio.SplitFunc interface
scanner.Split(v.split)
scanAndClose(scanner, writer)
return nil
}
func terminatePng(scanner *bufio.Scanner, writer io.WriteCloser) error {
ps := pngstructure.NewPngSplitter()