From b63676ff9319d78dfe6a3884beac2a53c45a548c Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 17 Oct 2024 10:31:21 +0200 Subject: [PATCH] Fix GeoGebra thumbnails when libvips support is enabled For GeoGebra files we where still using the imaging package to decode the embedded png, but handed it of to vips for scaling, which can't work. Now we use vips for decoding the image as well. --- services/thumbnails/pkg/errors/error.go | 2 ++ services/thumbnails/pkg/preprocessor/preprocessor.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/thumbnails/pkg/errors/error.go b/services/thumbnails/pkg/errors/error.go index e8bbe30889..c411130ce5 100644 --- a/services/thumbnails/pkg/errors/error.go +++ b/services/thumbnails/pkg/errors/error.go @@ -11,6 +11,8 @@ var ( ErrNoEncoderForType = errors.New("thumbnails: no encoder for this type found") // ErrNoImageFromAudioFile defines an error when an image cannot be extracted from an audio file ErrNoImageFromAudioFile = errors.New("thumbnails: could not extract image from audio file") + // ErrNoConverterForExtractedImageFromGgsFile defines an error when the extracted image from an ggs file could not be converted + ErrNoConverterForExtractedImageFromGgsFile = errors.New("thumbnails: could not find converter for image extracted from ggs file") // ErrNoConverterForExtractedImageFromAudioFile defines an error when the extracted image from an audio file could not be converted ErrNoConverterForExtractedImageFromAudioFile = errors.New("thumbnails: could not find converter for image extracted from audio file") // ErrCS3AuthorizationMissing defines an error when the CS3 authorization is missing diff --git a/services/thumbnails/pkg/preprocessor/preprocessor.go b/services/thumbnails/pkg/preprocessor/preprocessor.go index d4626b11e2..1733dcf835 100644 --- a/services/thumbnails/pkg/preprocessor/preprocessor.go +++ b/services/thumbnails/pkg/preprocessor/preprocessor.go @@ -12,7 +12,6 @@ import ( "mime" "strings" - "github.com/kovidgoyal/imaging" "github.com/pkg/errors" "golang.org/x/image/font" "golang.org/x/image/font/opentype" @@ -60,8 +59,11 @@ func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) { if err != nil { return nil, err } - - img, err := imaging.Decode(thumbnail, imaging.AutoOrientation(true)) + converter := ForType("image/png", nil) + if converter == nil { + return nil, thumbnailerErrors.ErrNoConverterForExtractedImageFromGgsFile + } + img, err := converter.Convert(thumbnail) if err != nil { return nil, errors.Wrap(err, `could not decode the image`) }