2023-12-23 00:09:23 +00:00
|
|
|
// Copyright (c) 2023 David Vogel
|
|
|
|
//
|
|
|
|
// This software is released under the MIT License.
|
|
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
|
2023-12-22 09:07:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-22 10:03:04 +00:00
|
|
|
"fmt"
|
2023-12-23 00:09:23 +00:00
|
|
|
"image"
|
2023-12-22 09:07:02 +00:00
|
|
|
"image/png"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-12-23 00:09:23 +00:00
|
|
|
func exportPNG(stitchedImage image.Image, outputPath string) error {
|
2023-12-22 10:03:04 +00:00
|
|
|
log.Printf("Creating output file %q.", outputPath)
|
|
|
|
f, err := os.Create(outputPath)
|
2023-12-22 09:07:02 +00:00
|
|
|
if err != nil {
|
2023-12-22 10:03:04 +00:00
|
|
|
return fmt.Errorf("failed to create file: %w", err)
|
2023-12-22 09:07:02 +00:00
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
encoder := png.Encoder{
|
|
|
|
CompressionLevel: png.DefaultCompression,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := encoder.Encode(f, stitchedImage); err != nil {
|
2023-12-22 10:03:04 +00:00
|
|
|
return fmt.Errorf("failed to encode image %q: %w", outputPath, err)
|
2023-12-22 09:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|