Skip to content

Commit

Permalink
Add JPEG encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Dec 22, 2023
1 parent a70a5a4 commit 0454e29
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/stitch/export-jpeg.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions bin/stitch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0454e29

Please sign in to comment.