From 9e8d03cbbce87a2b701c05600a67f75591e19027 Mon Sep 17 00:00:00 2001 From: Ignacio Rivero Date: Sun, 22 Jun 2025 17:13:48 -0300 Subject: [PATCH] Added stdout support --- main.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 7c1bf83..e53b4f0 100644 --- a/main.go +++ b/main.go @@ -449,11 +449,24 @@ func main() { case Mode4bpp: previewImg = renderPreviewFrom4bpp(pixels, linePixels, height) } - err = imaging.Save(previewImg, outputPath) - if err != nil { - log.Fatalf("Failed to save PNG preview: %v", err) + var out io.Writer + if outputPath == "-" { + out = os.Stdout + } else { + f, err := os.Create(outputPath) + if err != nil { + log.Fatalf("Failed to create output file: %v", err) + } + defer f.Close() + out = f + } + err = imaging.Encode(out, previewImg, imaging.PNG) + if err != nil { + log.Fatalf("Failed to write PNG preview: %v", err) + } + if outputPath != "-" { + fmt.Printf("Preview PNG written to %s\n", outputPath) } - fmt.Printf("Preview PNG written to %s\n", outputPath) return }