noita-mapcap/bin/stitch/export-jpeg.go
David Vogel 182373d3cc Refactor export functions
- Pass output path as parameter
- Return and handle errors correctly
2023-12-22 11:03:04 +01:00

28 lines
508 B
Go

package main
import (
"fmt"
"image/jpeg"
"log"
"os"
)
func exportJPEG(stitchedImage *StitchedImage, outputPath string) error {
log.Printf("Creating output file %q.", outputPath)
f, err := os.Create(outputPath)
if err != nil {
return fmt.Errorf("failed to create file: %w", err)
}
defer f.Close()
options := &jpeg.Options{
Quality: 80,
}
if err := jpeg.Encode(f, stitchedImage, options); err != nil {
return fmt.Errorf("failed to encode image %q: %w", outputPath, err)
}
return nil
}