noita-mapcap/bin/stitch/export-jpeg.go

28 lines
508 B
Go
Raw Normal View History

2023-12-22 09:13:22 +00:00
package main
import (
"fmt"
2023-12-22 09:13:22 +00:00
"image/jpeg"
"log"
"os"
)
func exportJPEG(stitchedImage *StitchedImage, outputPath string) error {
log.Printf("Creating output file %q.", outputPath)
f, err := os.Create(outputPath)
2023-12-22 09:13:22 +00:00
if err != nil {
return fmt.Errorf("failed to create file: %w", err)
2023-12-22 09:13:22 +00:00
}
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)
2023-12-22 09:13:22 +00:00
}
return nil
}