Add JPEG encoder

This commit is contained in:
David Vogel 2023-12-22 10:13:22 +01:00
parent a70a5a4d1a
commit 0454e29e34
2 changed files with 28 additions and 0 deletions

26
bin/stitch/export-jpeg.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"image/jpeg"
"log"
"os"
)
func exportJPEG(stitchedImage *StitchedImage) error {
log.Printf("Creating output file %q.", *flagOutputPath)
f, err := os.Create(*flagOutputPath)
if err != nil {
log.Panic(err)
}
defer f.Close()
options := &jpeg.Options{
Quality: 80,
}
if err := jpeg.Encode(f, stitchedImage, options); err != nil {
log.Panic(err)
}
return nil
}

View File

@ -270,6 +270,8 @@ func main() {
switch fileExtension {
case ".png":
exportPNG(stitchedImage)
case ".jpg", ".jpeg":
exportJPEG(stitchedImage)
default:
log.Panicf("Unknown output format %q.", fileExtension)
}