diff --git a/internal/imgcache/processor.go b/internal/imgcache/processor.go index 2eae104..08c79fb 100644 --- a/internal/imgcache/processor.go +++ b/internal/imgcache/processor.go @@ -6,10 +6,22 @@ import ( "errors" "fmt" "io" + "sync" "github.com/davidbyttow/govips/v2/vips" ) +// vipsOnce ensures vips is initialized exactly once. +var vipsOnce sync.Once + +// initVips initializes libvips with quiet logging. +func initVips() { + vipsOnce.Do(func() { + vips.LoggingSettings(nil, vips.LogLevelError) + vips.Startup(nil) + }) +} + // MaxInputDimension is the maximum allowed width or height for input images. // Images larger than this are rejected to prevent DoS via decompression bombs. const MaxInputDimension = 8192 @@ -25,6 +37,7 @@ type ImageProcessor struct{} // NewImageProcessor creates a new image processor. func NewImageProcessor() *ImageProcessor { + initVips() return &ImageProcessor{} } diff --git a/internal/imgcache/processor_test.go b/internal/imgcache/processor_test.go index 2c977c2..374826d 100644 --- a/internal/imgcache/processor_test.go +++ b/internal/imgcache/processor_test.go @@ -15,7 +15,7 @@ import ( ) func TestMain(m *testing.M) { - vips.Startup(nil) + initVips() code := m.Run() vips.Shutdown() os.Exit(code)