diff --git a/cmd/server/main.go b/cmd/server/main.go index c56ae5b..8f01cf8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -11,6 +11,7 @@ import ( "encoding/json" // Added for JSON handling "flag" "fmt" + "image" // "image" // Unused import removed _ "image/gif" // Ensure GIF support @@ -45,6 +46,7 @@ import ( "github.com/shirou/gopsutil/mem" "github.com/sirupsen/logrus" "github.com/spf13/viper" + "golang.org/x/image/webp" // Added for WEBP support "gopkg.in/natefinch/lumberjack.v2" ) @@ -2940,9 +2942,30 @@ func generateThumbnailWithFFmpeg(originalPath, thumbnailPath string, width, heig func generateThumbnailWithImaging(originalPath, thumbnailPath string, width, height int) error { // Open the original image - img, err := imaging.Open(originalPath) - if err != nil { - return fmt.Errorf("failed to open image: %v", err) + var img image.Image + var err error + + // Determine the file extension + ext := strings.ToLower(filepath.Ext(originalPath)) + + if ext == ".webp" { + // Open WEBP image using webp package + file, err := os.Open(originalPath) + if err != nil { + return fmt.Errorf("failed to open WEBP image: %w", err) + } + defer file.Close() + + img, err = webp.Decode(file) + if err != nil { + return fmt.Errorf("failed to decode WEBP image: %w", err) + } + } else { + // Open other image formats using imaging + img, err = imaging.Open(originalPath) + if err != nil { + return fmt.Errorf("failed to open image: %w", err) + } } // Resize the image using Lanczos filter diff --git a/go.mod b/go.mod index 9c4fe8b..1bf6a69 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect + golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 golang.org/x/sys v0.22.0 // indirect golang.org/x/term v0.17.0 // indirect golang.org/x/text v0.16.0 // indirect