Added stdout support

This commit is contained in:
Ignacio Rivero 2025-06-22 17:13:48 -03:00
parent d601461f48
commit 9e8d03cbbc

17
main.go
View File

@ -449,11 +449,24 @@ func main() {
case Mode4bpp: case Mode4bpp:
previewImg = renderPreviewFrom4bpp(pixels, linePixels, height) previewImg = renderPreviewFrom4bpp(pixels, linePixels, height)
} }
err = imaging.Save(previewImg, outputPath) var out io.Writer
if outputPath == "-" {
out = os.Stdout
} else {
f, err := os.Create(outputPath)
if err != nil { if err != nil {
log.Fatalf("Failed to save PNG preview: %v", err) 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 return
} }