From dd21f30a7f08044120fd2759881f0caca97c2082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20Bu=CC=88hrig?= Date: Fri, 11 Jul 2025 12:51:04 +0200 Subject: [PATCH] Save IR plot in same directory as IR file with matching filename --- pkg/convolve/convolve.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/convolve/convolve.go b/pkg/convolve/convolve.go index 58e2a5f..120b517 100644 --- a/pkg/convolve/convolve.go +++ b/pkg/convolve/convolve.go @@ -6,6 +6,7 @@ import ( "math" "math/cmplx" "os" + "strings" "image/png" @@ -642,8 +643,13 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error { p2.Draw(canvases[1][0]) dc.DrawImage(vg.Rectangle{Min: vg.Point{X: 0, Y: 0}, Max: vg.Point{X: width, Y: height}}, imgPlots.Image()) - // Save as PNG - f, err = os.Create("ir_plot.png") + // Save as PNG in the same directory as the IR file + irDir := filepath.Dir(irFileName) + irBase := filepath.Base(irFileName) + irNameWithoutExt := strings.TrimSuffix(irBase, filepath.Ext(irBase)) + plotFileName := filepath.Join(irDir, irNameWithoutExt+".png") + + f, err = os.Create(plotFileName) if err != nil { return err }